Commit 1bc4c0f3 authored by Tebjan Halm's avatar Tebjan Halm
Browse files

Merge pull request #92 from erdomke/master

Bug Fixes: Remove WPF dependency
Fix compilation error after merge I also worked on:
Add support for underline and strike through
Fix whitespace handling with text rendering
parents 535abaf8 2187be3e
......@@ -195,6 +195,16 @@ namespace Svg
set { this.Attributes["font-variant"] = value; this.IsPathDirty = true; }
}
/// <summary>
/// Refers to the boldness of the font.
/// </summary>
[SvgAttribute("text-decoration")]
public virtual SvgTextDecoration TextDecoration
{
get { return (this.Attributes["text-decoration"] == null) ? SvgTextDecoration.inherit : (SvgTextDecoration)this.Attributes["text-decoration"]; }
set { this.Attributes["text-decoration"] = value; this.IsPathDirty = true; }
}
/// <summary>
/// Refers to the boldness of the font.
/// </summary>
......@@ -323,6 +333,7 @@ namespace Svg
{
case SvgFontWeight.bold:
case SvgFontWeight.bolder:
case SvgFontWeight.w600:
case SvgFontWeight.w700:
case SvgFontWeight.w800:
case SvgFontWeight.w900:
......@@ -339,6 +350,17 @@ namespace Svg
break;
}
// Get the text-decoration
switch (this.TextDecoration)
{
case SvgTextDecoration.lineThrough:
fontStyle |= System.Drawing.FontStyle.Strikeout;
break;
case SvgTextDecoration.underline:
fontStyle |= System.Drawing.FontStyle.Underline;
break;
}
// Get the font-family
string family = ValidateFontFamily(this.FontFamily) ?? DefaultFontFamily;
return new System.Drawing.Font(family, fontSize, fontStyle, System.Drawing.GraphicsUnit.Pixel);
......
......@@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.ComponentModel;
namespace Svg.DataTypes
namespace Svg
{
[TypeConverter(typeof(SvgFontVariantConverter))]
public enum SvgFontVariant
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace Svg
{
[TypeConverter(typeof(SvgTextDecorationConverter))]
public enum SvgTextDecoration
{
inherit,
none,
underline,
overline,
lineThrough,
blink
}
}
......@@ -116,11 +116,11 @@ namespace Svg
if (currFont == null)
{
points = (float)(value * 9);
_deviceValue = (points / 72) * ppi;
_deviceValue = (points / 72.0f) * ppi;
}
else
{
_deviceValue = value * (currFont.SizeInPoints / 72) * ppi;
_deviceValue = value * (currFont.SizeInPoints / 72.0f) * ppi;
}
break;
case SvgUnitType.Ex:
......@@ -128,11 +128,11 @@ namespace Svg
if (currFont == null)
{
points = (float)(value * 9);
_deviceValue = (points / 72) * ppi / 2;
_deviceValue = (points * 0.5f / 72.0f) * ppi;
}
else
{
_deviceValue = value * (currFont.SizeInPoints / 72) * ppi * RelativeXHeight(currFont);
_deviceValue = value * 0.5f * (currFont.SizeInPoints / 72.0f) * ppi;
}
break;
case SvgUnitType.Centimeter:
......@@ -200,18 +200,6 @@ namespace Svg
var visual = owner.ParentsAndSelf.OfType<SvgVisualElement>().FirstOrDefault();
return visual.GetFont(renderer);
}
private float RelativeXHeight(Font font)
{
var mediaFont = new System.Windows.Media.FontFamily(font.Name);
var sum = 0.0;
var cnt = 0;
foreach (var tf in mediaFont.FamilyTypefaces)
{
sum += tf.XHeight;
cnt += 1;
}
return (float)(sum / cnt);
}
/// <summary>
/// Converts the current unit to a percentage, if applicable.
......
......@@ -137,6 +137,23 @@ namespace Svg
}
}
public sealed class SvgTextDecorationConverter : EnumBaseConverter<SvgTextDecoration>
{
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value.ToString() == "line-through") return SvgTextDecoration.lineThrough;
return base.ConvertFrom(context, culture, value);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string) && value is SvgTextDecoration && (SvgTextDecoration)value == SvgTextDecoration.lineThrough)
{
return "line-through";
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
public sealed class SvgFontWeightConverter : EnumBaseConverter<SvgFontWeight>
{
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
......
......@@ -82,7 +82,6 @@
<AssemblyOriginatorKeyFile>svgkey.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="PresentationCore" />
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
......@@ -101,6 +100,7 @@
<Compile Include="Clipping and Masking\SvgClipPath.cs" />
<Compile Include="Clipping and Masking\SvgMask.cs" />
<Compile Include="DataTypes\ISvgSupportsCoordinateUnits.cs" />
<Compile Include="DataTypes\SvgTextDecoration.cs" />
<Compile Include="Painting\GenericBoundable.cs" />
<Compile Include="SvgNodeReader.cs" />
<Compile Include="Css\CssQuery.cs" />
......@@ -231,7 +231,6 @@
<Compile Include="SvgContentNode.cs" />
<Compile Include="SvgDefinitionDefaults.cs" />
<Compile Include="NonSvgElement.cs" />
<Compile Include="SvgReader.cs" />
<Compile Include="SvgUnknownElement.cs" />
<Compile Include="SvgElementAttribute.cs" />
<Compile Include="SvgExtentions.cs" />
......
......@@ -87,7 +87,9 @@ namespace Svg
return (value == null ||
(value is SvgFontStyle && (SvgFontStyle)value == SvgFontStyle.inherit) ||
(value is SvgFontWeight && (SvgFontWeight)value == SvgFontWeight.inherit) ||
(value is SvgTextAnchor && (SvgTextAnchor)value == SvgTextAnchor.inherit) ||
(value is SvgTextAnchor && (SvgTextAnchor)value == SvgTextAnchor.inherit) ||
(value is SvgFontVariant && (SvgFontVariant)value == SvgFontVariant.inherit) ||
(value is SvgTextDecoration && (SvgTextDecoration)value == SvgTextDecoration.inherit) ||
(value == "inherit")
);
}
......
......@@ -447,7 +447,7 @@ namespace Svg
{
using (var renderer = SvgRenderer.FromImage(bitmap))
{
renderer.Boundable(this);
renderer.Boundable(new GenericBoundable(0, 0, bitmap.Width, bitmap.Height));
renderer.TextRenderingHint = TextRenderingHint.AntiAlias;
renderer.TextContrast = 1;
renderer.PixelOffsetMode = PixelOffsetMode.Half;
......
......@@ -441,8 +441,8 @@ namespace Svg
else
{
var convValue = MultipleSpaces.Replace(value.Replace("\r", "").Replace("\n", "").Replace('\t', ' '), " ");
if (!leadingSpace) convValue = convValue.TrimStart();
if (!trailingSpace) convValue = convValue.TrimEnd();
//if (!leadingSpace) convValue = convValue.TrimStart();
//if (!trailingSpace) convValue = convValue.TrimEnd();
return convValue;
}
}
......
......@@ -32,18 +32,18 @@
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.tableLayoutPanel2 = new System.Windows.Forms.TableLayoutPanel();
this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.picSvg = new System.Windows.Forms.PictureBox();
this.tableLayoutPanel3 = new System.Windows.Forms.TableLayoutPanel();
this.picPng = new System.Windows.Forms.PictureBox();
this.label2 = new System.Windows.Forms.Label();
this.tableLayoutPanel1.SuspendLayout();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.tableLayoutPanel2.SuspendLayout();
this.tableLayoutPanel3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.picSvg)).BeginInit();
this.tableLayoutPanel3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.picPng)).BeginInit();
this.SuspendLayout();
//
......@@ -53,14 +53,14 @@
this.lstFiles.FormattingEnabled = true;
this.lstFiles.Location = new System.Drawing.Point(3, 3);
this.lstFiles.Name = "lstFiles";
this.lstFiles.Size = new System.Drawing.Size(144, 376);
this.lstFiles.Size = new System.Drawing.Size(174, 670);
this.lstFiles.TabIndex = 0;
this.lstFiles.SelectedIndexChanged += new System.EventHandler(this.lstFiles_SelectedIndexChanged);
//
// tableLayoutPanel1
//
this.tableLayoutPanel1.ColumnCount = 2;
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 150F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 180F));
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Controls.Add(this.splitContainer1, 1, 0);
this.tableLayoutPanel1.Controls.Add(this.lstFiles, 0, 0);
......@@ -69,13 +69,13 @@
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
this.tableLayoutPanel1.RowCount = 1;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(977, 382);
this.tableLayoutPanel1.Size = new System.Drawing.Size(1235, 676);
this.tableLayoutPanel1.TabIndex = 1;
//
// splitContainer1
//
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.Location = new System.Drawing.Point(153, 3);
this.splitContainer1.Location = new System.Drawing.Point(183, 3);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
......@@ -85,8 +85,8 @@
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.tableLayoutPanel3);
this.splitContainer1.Size = new System.Drawing.Size(821, 376);
this.splitContainer1.SplitterDistance = 424;
this.splitContainer1.Size = new System.Drawing.Size(1049, 670);
this.splitContainer1.SplitterDistance = 541;
this.splitContainer1.TabIndex = 0;
//
// tableLayoutPanel2
......@@ -101,24 +101,9 @@
this.tableLayoutPanel2.RowCount = 2;
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel2.Size = new System.Drawing.Size(424, 376);
this.tableLayoutPanel2.Size = new System.Drawing.Size(541, 670);
this.tableLayoutPanel2.TabIndex = 0;
//
// tableLayoutPanel3
//
this.tableLayoutPanel3.ColumnCount = 1;
this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel3.Controls.Add(this.picPng, 0, 1);
this.tableLayoutPanel3.Controls.Add(this.label2, 0, 0);
this.tableLayoutPanel3.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel3.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel3.Name = "tableLayoutPanel3";
this.tableLayoutPanel3.RowCount = 2;
this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel3.Size = new System.Drawing.Size(393, 376);
this.tableLayoutPanel3.TabIndex = 0;
//
// label1
//
this.label1.AutoSize = true;
......@@ -128,15 +113,6 @@
this.label1.TabIndex = 0;
this.label1.Text = "SVG Render";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(3, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(68, 13);
this.label2.TabIndex = 0;
this.label2.Text = "PNG Render";
//
// picSvg
//
this.picSvg.BackColor = System.Drawing.Color.White;
......@@ -144,10 +120,25 @@
this.picSvg.Location = new System.Drawing.Point(0, 13);
this.picSvg.Margin = new System.Windows.Forms.Padding(0);
this.picSvg.Name = "picSvg";
this.picSvg.Size = new System.Drawing.Size(424, 363);
this.picSvg.Size = new System.Drawing.Size(541, 657);
this.picSvg.TabIndex = 1;
this.picSvg.TabStop = false;
//
// tableLayoutPanel3
//
this.tableLayoutPanel3.ColumnCount = 1;
this.tableLayoutPanel3.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel3.Controls.Add(this.picPng, 0, 1);
this.tableLayoutPanel3.Controls.Add(this.label2, 0, 0);
this.tableLayoutPanel3.Dock = System.Windows.Forms.DockStyle.Fill;
this.tableLayoutPanel3.Location = new System.Drawing.Point(0, 0);
this.tableLayoutPanel3.Name = "tableLayoutPanel3";
this.tableLayoutPanel3.RowCount = 2;
this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle());
this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
this.tableLayoutPanel3.Size = new System.Drawing.Size(504, 670);
this.tableLayoutPanel3.TabIndex = 0;
//
// picPng
//
this.picPng.BackColor = System.Drawing.Color.White;
......@@ -155,17 +146,26 @@
this.picPng.Location = new System.Drawing.Point(0, 13);
this.picPng.Margin = new System.Windows.Forms.Padding(0);
this.picPng.Name = "picPng";
this.picPng.Size = new System.Drawing.Size(393, 363);
this.picPng.Size = new System.Drawing.Size(504, 657);
this.picPng.TabIndex = 2;
this.picPng.TabStop = false;
//
// frmView
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(3, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(68, 13);
this.label2.TabIndex = 0;
this.label2.Text = "PNG Render";
//
// View
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(977, 382);
this.ClientSize = new System.Drawing.Size(1235, 676);
this.Controls.Add(this.tableLayoutPanel1);
this.Name = "frmView";
this.Name = "View";
this.Text = "Form1";
this.tableLayoutPanel1.ResumeLayout(false);
this.splitContainer1.Panel1.ResumeLayout(false);
......@@ -173,9 +173,9 @@
this.splitContainer1.ResumeLayout(false);
this.tableLayoutPanel2.ResumeLayout(false);
this.tableLayoutPanel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.picSvg)).EndInit();
this.tableLayoutPanel3.ResumeLayout(false);
this.tableLayoutPanel3.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.picSvg)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.picPng)).EndInit();
this.ResumeLayout(false);
......
......@@ -29,8 +29,19 @@ namespace SvgW3CTestRunner
private void lstFiles_SelectedIndexChanged(object sender, EventArgs e)
{
var fileName = lstFiles.SelectedItem.ToString();
var doc = SvgDocument.Open(_svgBasePath + fileName);
picSvg.Image = doc.Draw();
try
{
var doc = SvgDocument.Open(_svgBasePath + fileName);
var img = new Bitmap(480, 360);
doc.Draw(img);
picSvg.Image = img;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
picSvg.Image = null;
}
var png = Image.FromFile(_pngBasePath + Path.GetFileNameWithoutExtension(fileName) + ".png");
picPng.Image = png;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment