diff --git a/Source/Basic Shapes/SvgVisualElementStyle.cs b/Source/Basic Shapes/SvgVisualElementStyle.cs index a09fa748f71a27d2fdd06a7e0ae94931ef32c5db..17884638af7e74f7c0c95d986bea4c140bd88e47 100644 --- a/Source/Basic Shapes/SvgVisualElementStyle.cs +++ b/Source/Basic Shapes/SvgVisualElementStyle.cs @@ -195,6 +195,16 @@ namespace Svg set { this.Attributes["font-variant"] = value; this.IsPathDirty = true; } } + /// + /// Refers to the boldness of the font. + /// + [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; } + } + /// /// Refers to the boldness of the font. /// @@ -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); diff --git a/Source/DataTypes/SvgFontVariant.cs b/Source/DataTypes/SvgFontVariant.cs index 5f1d44b93d757bb1267cce77fa4fdd3aca0563e8..40971b83cb6d73b2f91b6d648a48ecb0e9155d5e 100644 --- a/Source/DataTypes/SvgFontVariant.cs +++ b/Source/DataTypes/SvgFontVariant.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.ComponentModel; -namespace Svg.DataTypes +namespace Svg { [TypeConverter(typeof(SvgFontVariantConverter))] public enum SvgFontVariant diff --git a/Source/DataTypes/SvgTextDecoration.cs b/Source/DataTypes/SvgTextDecoration.cs new file mode 100644 index 0000000000000000000000000000000000000000..50f9523247a7c8dad3b0e40cfb1100ca4015cec9 --- /dev/null +++ b/Source/DataTypes/SvgTextDecoration.cs @@ -0,0 +1,19 @@ +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 + } +} diff --git a/Source/DataTypes/SvgUnit.cs b/Source/DataTypes/SvgUnit.cs index 30a7c5965ebe7967422332a766c8aed9d0b9cc4d..9fb4f50c5a59de66ce0862f712ed79f93298cdc2 100644 --- a/Source/DataTypes/SvgUnit.cs +++ b/Source/DataTypes/SvgUnit.cs @@ -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().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); - } /// /// Converts the current unit to a percentage, if applicable. diff --git a/Source/Painting/EnumConverters.cs b/Source/Painting/EnumConverters.cs index 75fe2573660a5b978d21103266f0abd6e460b0cb..b0f66362ff2560ac384c0b13a492b74265bc97d7 100644 --- a/Source/Painting/EnumConverters.cs +++ b/Source/Painting/EnumConverters.cs @@ -137,6 +137,23 @@ namespace Svg } } + public sealed class SvgTextDecorationConverter : EnumBaseConverter + { + 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 { public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) diff --git a/Source/Svg.csproj b/Source/Svg.csproj index c344e84bba1aa78e244d281e91374e3c2b325558..b66ced056eb9248b51f1f15b62a0e9288c8196d5 100644 --- a/Source/Svg.csproj +++ b/Source/Svg.csproj @@ -82,7 +82,6 @@ svgkey.snk - @@ -101,6 +100,7 @@ + @@ -231,7 +231,6 @@ - diff --git a/Source/SvgAttributeCollection.cs b/Source/SvgAttributeCollection.cs index aaf910cbc8001d8b3ca05afcc5fc7a781db2031c..db60897651b574f6c60ff777c33028d8e551c430 100644 --- a/Source/SvgAttributeCollection.cs +++ b/Source/SvgAttributeCollection.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") ); } diff --git a/Source/SvgDocument.cs b/Source/SvgDocument.cs index 9dc6303d31e19c93ebb14c879e9786616944d525..c5fd0dcbb266f1724667364b2e7eb7fe0613a463 100644 --- a/Source/SvgDocument.cs +++ b/Source/SvgDocument.cs @@ -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; diff --git a/Source/Text/SvgTextBase.cs b/Source/Text/SvgTextBase.cs index f1315d720f27cedcb60f7d008ffe499c9584ec78..35040b7de16219e0691de54421ed191e005ffb1c 100644 --- a/Source/Text/SvgTextBase.cs +++ b/Source/Text/SvgTextBase.cs @@ -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; } } diff --git a/Tests/SvgW3CTestRunner/View.Designer.cs b/Tests/SvgW3CTestRunner/View.Designer.cs index bd05a7836f946c9057ab693144cab32bb3e919b4..27ea5138d80802d6887e16f9ab88443567c00934 100644 --- a/Tests/SvgW3CTestRunner/View.Designer.cs +++ b/Tests/SvgW3CTestRunner/View.Designer.cs @@ -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); diff --git a/Tests/SvgW3CTestRunner/View.cs b/Tests/SvgW3CTestRunner/View.cs index 786325f8a72e40026e5d41a8a922acba3f477d33..8a09148032254e9ccf41adf9f51964f63d3d98f8 100644 --- a/Tests/SvgW3CTestRunner/View.cs +++ b/Tests/SvgW3CTestRunner/View.cs @@ -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; }