Commit 968a8f43 authored by Eric Domke's avatar Eric Domke
Browse files

Iteration 2 of tspan functionality

- Support more font styles
- Fix problems with parsing 'em' svg units introduced by trying to parse
2e-5 double formats
- Move font properties to SvgVisualElement class as grouping elements
can also contain them
- Properly inherit font properties via the parent list
- Properly handle tspan offsets
- Support for .Net 3.5
parent ceb78a3f
...@@ -3,6 +3,9 @@ using System.Collections.Generic; ...@@ -3,6 +3,9 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.Reflection; using System.Reflection;
using System.ComponentModel; using System.ComponentModel;
using Svg.DataTypes;
using System.Text.RegularExpressions;
using System.Linq;
namespace Svg namespace Svg
{ {
...@@ -151,5 +154,159 @@ namespace Svg ...@@ -151,5 +154,159 @@ namespace Svg
get { return (this.Attributes["opacity"] == null) ? 1.0f : (float)this.Attributes["opacity"]; } get { return (this.Attributes["opacity"] == null) ? 1.0f : (float)this.Attributes["opacity"]; }
set { this.Attributes["opacity"] = FixOpacityValue(value); } set { this.Attributes["opacity"] = FixOpacityValue(value); }
} }
/// <summary>
/// Indicates which font family is to be used to render the text.
/// </summary>
[SvgAttribute("font-family")]
public virtual string FontFamily
{
get { return this.Attributes["font-family"] as string; }
set
{
this.Attributes["font-family"] = value;
this.IsPathDirty = true;
}
}
/// <summary>
/// Refers to the size of the font from baseline to baseline when multiple lines of text are set solid in a multiline layout environment.
/// </summary>
[SvgAttribute("font-size")]
public virtual SvgUnit FontSize
{
get { return (this.Attributes["font-size"] == null) ? SvgUnit.Empty : (SvgUnit)this.Attributes["font-size"]; }
set { this.Attributes["font-size"] = value; this.IsPathDirty = true; }
}
public SvgUnit GetInheritedFontSize()
{
var fontSizeElement = (from e in this.ParentsAndSelf.OfType<SvgVisualElement>()
where e.FontSize != SvgUnit.Empty && e.FontSize != SvgUnit.None
select e).FirstOrDefault();
return (fontSizeElement == null ? SvgUnit.None : fontSizeElement.FontSize);
}
/// <summary>
/// Refers to the boldness of the font.
/// </summary>
[SvgAttribute("font-style")]
public virtual SvgFontStyle FontStyle
{
get { return (this.Attributes["font-style"] == null) ? SvgFontStyle.inherit : (SvgFontStyle)this.Attributes["font-style"]; }
set { this.Attributes["font-style"] = value; this.IsPathDirty = true; }
}
/// <summary>
/// Refers to the boldness of the font.
/// </summary>
[SvgAttribute("font-variant")]
public virtual SvgFontVariant FontVariant
{
get { return (this.Attributes["font-variant"] == null) ? SvgFontVariant.inherit : (SvgFontVariant)this.Attributes["font-variant"]; }
set { this.Attributes["font-variant"] = value; this.IsPathDirty = true; }
}
/// <summary>
/// Refers to the boldness of the font.
/// </summary>
[SvgAttribute("font-weight")]
public virtual SvgFontWeight FontWeight
{
get { return (this.Attributes["font-weight"] == null) ? SvgFontWeight.inherit : (SvgFontWeight)this.Attributes["font-weight"]; }
set { this.Attributes["font-weight"] = value; this.IsPathDirty = true; }
}
private enum FontParseState
{
fontStyle,
fontVariant,
fontWeight,
fontSize,
fontFamilyNext,
fontFamilyCurr
}
/// <summary>
/// Set all font information.
/// </summary>
[SvgAttribute("font")]
public virtual string Font
{
get { return (this.Attributes["font"] == null ? "" : this.Attributes["font"] as string); }
set
{
var state = FontParseState.fontStyle;
var parts = value.Split(' ');
SvgFontStyle fontStyle;
SvgFontVariant fontVariant;
SvgFontWeight fontWeight;
SvgUnit fontSize;
bool success;
string[] sizes;
string part;
for (int i = 0; i < parts.Length; i++)
{
part = parts[i];
success = false;
while (!success)
{
switch (state)
{
case FontParseState.fontStyle:
success = Enums.TryParse<SvgFontStyle>(part, out fontStyle);
if (success) this.FontStyle = fontStyle;
state++;
break;
case FontParseState.fontVariant:
success = Enums.TryParse<SvgFontVariant>(part, out fontVariant);
if (success) this.FontVariant = fontVariant;
state++;
break;
case FontParseState.fontWeight:
success = Enums.TryParse<SvgFontWeight>(part, out fontWeight);
if (success) this.FontWeight = fontWeight;
state++;
break;
case FontParseState.fontSize:
sizes = part.Split('/');
try
{
fontSize = (SvgUnit)(new SvgUnitConverter().ConvertFromInvariantString(sizes[0]));
success = true;
this.FontSize = fontSize;
}
catch { }
state++;
break;
case FontParseState.fontFamilyNext:
state++;
success = true;
break;
}
}
switch (state)
{
case FontParseState.fontFamilyNext:
this.FontFamily = string.Join(" ", parts, i + 1, parts.Length - (i + 1));
i = int.MaxValue;
break;
case FontParseState.fontFamilyCurr:
this.FontFamily = string.Join(" ", parts, i, parts.Length - (i));
i = int.MaxValue;
break;
}
}
this.Attributes["font"] = value;
this.IsPathDirty = true;
}
}
} }
} }
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Svg
{
public enum SvgFontStyle
{
normal,
italic,
oblique,
inherit
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace Svg.DataTypes
{
[TypeConverter(typeof(SvgFontVariantConverter))]
public enum SvgFontVariant
{
normal,
smallcaps,
inherit
}
}
...@@ -2,13 +2,26 @@ ...@@ -2,13 +2,26 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.ComponentModel;
namespace Svg.DataTypes namespace Svg
{ {
[TypeConverter(typeof(SvgFontWeightConverter))]
public enum SvgFontWeight public enum SvgFontWeight
{ {
inherit, inherit,
normal, normal,
bold bold,
bolder,
lighter,
w100,
w200,
w300,
w400, // same as normal
w500,
w600,
w700, // same as bold
w800,
w900
} }
} }
...@@ -102,8 +102,16 @@ namespace Svg ...@@ -102,8 +102,16 @@ namespace Svg
switch (this.Type) switch (this.Type)
{ {
case SvgUnitType.Em: case SvgUnitType.Em:
var visualElem = boundable as SvgVisualElement;
if (visualElem == null)
{
float points = (float)(this.Value * 9); float points = (float)(this.Value * 9);
_deviceValue = (points / 72) * ppi; _deviceValue = (points / 72) * ppi;
}
else
{
_deviceValue = this.Value * visualElem.GetInheritedFontSize().ToDeviceValue(boundable);
}
break; break;
case SvgUnitType.Centimeter: case SvgUnitType.Centimeter:
_deviceValue = (float)((this.Value / cmInInch) * ppi); _deviceValue = (float)((this.Value / cmInInch) * ppi);
......
...@@ -23,13 +23,6 @@ namespace Svg ...@@ -23,13 +23,6 @@ namespace Svg
throw new ArgumentOutOfRangeException("value must be a string."); throw new ArgumentOutOfRangeException("value must be a string.");
} }
//support exponents (the SVG that comes back from IE may be an exponent ugh!!!)
if ((value as string).Contains("e"))
{
var d = Decimal.Parse((string)value, System.Globalization.NumberStyles.Float);
value = d.ToString();
}
// http://www.w3.org/TR/CSS21/syndata.html#values // http://www.w3.org/TR/CSS21/syndata.html#values
// http://www.w3.org/TR/SVG11/coords.html#Units // http://www.w3.org/TR/SVG11/coords.html#Units
...@@ -41,7 +34,8 @@ namespace Svg ...@@ -41,7 +34,8 @@ namespace Svg
for (int i = 0; i < unit.Length; i++) for (int i = 0; i < unit.Length; i++)
{ {
if (char.IsLetter(unit[i]) || unit[i] == '%') // If the character is a percent sign or a letter which is not an exponent 'e'
if (unit[i] == '%' || (char.IsLetter(unit[i]) && !(unit[i] == 'e' && i < unit.Length - 1 && !char.IsLetter(unit[i + 1]))))
{ {
identifierIndex = i; identifierIndex = i;
break; break;
......
...@@ -5,7 +5,6 @@ using System.Globalization; ...@@ -5,7 +5,6 @@ using System.Globalization;
namespace Svg namespace Svg
{ {
//just overrrides canconvert and returns true //just overrrides canconvert and returns true
public class BaseConverter : TypeConverter public class BaseConverter : TypeConverter
{ {
...@@ -120,4 +119,77 @@ namespace Svg ...@@ -120,4 +119,77 @@ namespace Svg
public sealed class SvgMarkerUnitsConverter : EnumBaseConverter<SvgMarkerUnits> public sealed class SvgMarkerUnitsConverter : EnumBaseConverter<SvgMarkerUnits>
{ {
} }
public sealed class SvgFontVariantConverter : EnumBaseConverter<SvgFontVariant>
{
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value == "small-caps") return SvgFontVariant.smallcaps;
return base.ConvertFrom(context, culture, value);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string) && value is SvgFontVariant && (SvgFontVariant)value == SvgFontVariant.smallcaps)
{
return "small-caps";
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
public sealed class SvgFontWeightConverter : EnumBaseConverter<SvgFontWeight>
{
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
{
switch ((string)value)
{
case "100": return SvgFontWeight.w100;
case "200": return SvgFontWeight.w200;
case "300": return SvgFontWeight.w300;
case "400": return SvgFontWeight.w400;
case "500": return SvgFontWeight.w500;
case "600": return SvgFontWeight.w600;
case "700": return SvgFontWeight.w700;
case "800": return SvgFontWeight.w800;
case "900": return SvgFontWeight.w900;
}
}
return base.ConvertFrom(context, culture, value);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string) && value is SvgFontWeight)
{
switch ((SvgFontWeight)value)
{
case SvgFontWeight.w100: return "100";
case SvgFontWeight.w200: return "200";
case SvgFontWeight.w300: return "300";
case SvgFontWeight.w400: return "400";
case SvgFontWeight.w500: return "500";
case SvgFontWeight.w600: return "600";
case SvgFontWeight.w700: return "700";
case SvgFontWeight.w800: return "800";
case SvgFontWeight.w900: return "900";
}
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
public static class Enums
{
public static bool TryParse<TEnum>(string value, out TEnum result) where TEnum : struct, IConvertible
{
var retValue = value == null ?
false :
Enum.IsDefined(typeof(TEnum), value);
result = retValue ?
(TEnum)Enum.Parse(typeof(TEnum), value) :
default(TEnum);
return retValue;
}
}
} }
...@@ -98,8 +98,8 @@ namespace Svg ...@@ -98,8 +98,8 @@ namespace Svg
if (NeedToExpandGradient(renderingElement, specifiedStart, specifiedEnd)) if (NeedToExpandGradient(renderingElement, specifiedStart, specifiedEnd))
{ {
var expansion = ExpandGradient(renderingElement, specifiedStart, specifiedEnd); var expansion = ExpandGradient(renderingElement, specifiedStart, specifiedEnd);
effectiveStart = expansion.Item1; effectiveStart = expansion.StartPoint;
effectiveEnd = expansion.Item2; effectiveEnd = expansion.EndPoint;
} }
return new LinearGradientBrush(effectiveStart, effectiveEnd, Color.Transparent, Color.Transparent) return new LinearGradientBrush(effectiveStart, effectiveEnd, Color.Transparent, Color.Transparent)
...@@ -124,12 +124,24 @@ namespace Svg ...@@ -124,12 +124,24 @@ namespace Svg
return SpreadMethod == SvgGradientSpreadMethod.Pad && (boundable.Bounds.Contains(specifiedStart) || boundable.Bounds.Contains(specifiedEnd)); return SpreadMethod == SvgGradientSpreadMethod.Pad && (boundable.Bounds.Contains(specifiedStart) || boundable.Bounds.Contains(specifiedEnd));
} }
private Tuple<PointF, PointF> ExpandGradient(ISvgBoundable boundable, PointF specifiedStart, PointF specifiedEnd) public struct GradientPoints
{
public PointF StartPoint;
public PointF EndPoint;
public GradientPoints(PointF startPoint, PointF endPoint)
{
this.StartPoint = startPoint;
this.EndPoint = endPoint;
}
}
private GradientPoints ExpandGradient(ISvgBoundable boundable, PointF specifiedStart, PointF specifiedEnd)
{ {
if (!NeedToExpandGradient(boundable, specifiedStart, specifiedEnd)) if (!NeedToExpandGradient(boundable, specifiedStart, specifiedEnd))
{ {
Debug.Fail("Unexpectedly expanding gradient when not needed!"); Debug.Fail("Unexpectedly expanding gradient when not needed!");
return new Tuple<PointF, PointF>(specifiedStart, specifiedEnd); return new GradientPoints(specifiedStart, specifiedEnd);
} }
var specifiedLength = CalculateDistance(specifiedStart, specifiedEnd); var specifiedLength = CalculateDistance(specifiedStart, specifiedEnd);
...@@ -159,7 +171,7 @@ namespace Svg ...@@ -159,7 +171,7 @@ namespace Svg
effectiveEnd = MovePointAlongVector(effectiveEnd, specifiedUnitVector, 1); effectiveEnd = MovePointAlongVector(effectiveEnd, specifiedUnitVector, 1);
} }
return new Tuple<PointF, PointF>(effectiveStart, effectiveEnd); return new GradientPoints(effectiveStart, effectiveEnd);
} }
private ColorBlend CalculateColorBlend(SvgVisualElement owner, float opacity, PointF specifiedStart, PointF effectiveStart, PointF specifiedEnd, PointF effectiveEnd) private ColorBlend CalculateColorBlend(SvgVisualElement owner, float opacity, PointF specifiedStart, PointF effectiveStart, PointF specifiedEnd, PointF effectiveEnd)
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
<OldToolsVersion>3.5</OldToolsVersion> <OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation> <UpgradeBackupLocation>
</UpgradeBackupLocation> </UpgradeBackupLocation>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<IsWebBootstrapper>false</IsWebBootstrapper> <IsWebBootstrapper>false</IsWebBootstrapper>
<SccProjectName> <SccProjectName>
</SccProjectName> </SccProjectName>
...@@ -100,6 +100,8 @@ ...@@ -100,6 +100,8 @@
<Compile Include="Clipping and Masking\SvgClipPath.cs" /> <Compile Include="Clipping and Masking\SvgClipPath.cs" />
<Compile Include="Clipping and Masking\SvgMask.cs" /> <Compile Include="Clipping and Masking\SvgMask.cs" />
<Compile Include="DataTypes\SvgAspectRatioConverter.cs" /> <Compile Include="DataTypes\SvgAspectRatioConverter.cs" />
<Compile Include="DataTypes\SvgFontStyle.cs" />
<Compile Include="DataTypes\SvgFontVariant.cs" />
<Compile Include="DataTypes\SvgMarkerUnits.cs" /> <Compile Include="DataTypes\SvgMarkerUnits.cs" />
<Compile Include="DataTypes\SvgOrient.cs" /> <Compile Include="DataTypes\SvgOrient.cs" />
<Compile Include="DataTypes\ISvgViewPort.cs" /> <Compile Include="DataTypes\ISvgViewPort.cs" />
......
...@@ -149,6 +149,32 @@ namespace Svg ...@@ -149,6 +149,32 @@ namespace Svg
get { return this._parent; } get { return this._parent; }
} }
public IEnumerable<SvgElement> Parents
{
get
{
var curr = this;
while (curr.Parent != null)
{
curr = curr.Parent;
yield return curr;
}
}
}
public IEnumerable<SvgElement> ParentsAndSelf
{
get
{
var curr = this;
yield return curr;
while (curr.Parent != null)
{
curr = curr.Parent;
yield return curr;
}
}
}
/// <summary> /// <summary>
/// Gets the owner <see cref="SvgDocument"/>. /// Gets the owner <see cref="SvgDocument"/>.
/// </summary> /// </summary>
......
...@@ -25,10 +25,6 @@ namespace Svg ...@@ -25,10 +25,6 @@ namespace Svg
private SvgUnit _dx; private SvgUnit _dx;
private SvgUnit _letterSpacing; private SvgUnit _letterSpacing;
private SvgUnit _wordSpacing; private SvgUnit _wordSpacing;
private SvgUnit _fontSize;
private SvgFontWeight _fontWeight;
private string _font;
protected string _fontFamily;
private SvgTextAnchor _textAnchor = SvgTextAnchor.Start; private SvgTextAnchor _textAnchor = SvgTextAnchor.Start;
private static readonly SvgRenderer _stringMeasure; private static readonly SvgRenderer _stringMeasure;
private const string DefaultFontFamily = "Times New Roman"; private const string DefaultFontFamily = "Times New Roman";
...@@ -50,7 +46,6 @@ namespace Svg ...@@ -50,7 +46,6 @@ namespace Svg
/// </summary> /// </summary>
public SvgTextBase() public SvgTextBase()
{ {
this._fontSize = new SvgUnit(0.0f);
this._dy = new SvgUnit(0.0f); this._dy = new SvgUnit(0.0f);
this._dx = new SvgUnit(0.0f); this._dx = new SvgUnit(0.0f);
} }
...@@ -171,80 +166,6 @@ namespace Svg ...@@ -171,80 +166,6 @@ namespace Svg
set { this._wordSpacing = value; this.IsPathDirty = true; } set { this._wordSpacing = value; this.IsPathDirty = true; }
} }
/// <summary>
/// Indicates which font family is to be used to render the text.
/// </summary>
[SvgAttribute("font-family")]
public virtual string FontFamily
{
get { return this._fontFamily ?? DefaultFontFamily; }
set
{
this._fontFamily = ValidateFontFamily(value);
this.IsPathDirty = true;
}
}
/// <summary>
/// Refers to the size of the font from baseline to baseline when multiple lines of text are set solid in a multiline layout environment.
/// </summary>
[SvgAttribute("font-size")]
public virtual SvgUnit FontSize
{
get { return this._fontSize; }
set { this._fontSize = value; this.IsPathDirty = true; }
}
/// <summary>
/// Refers to the boldness of the font.
/// </summary>
[SvgAttribute("font-weight")]
public virtual SvgFontWeight FontWeight
{
get { return this._fontWeight; }
set { this._fontWeight = value; this.IsPathDirty = true; }
}
/// <summary>
/// Set all font information.
/// </summary>
[SvgAttribute("font")]
public virtual string Font
{
get { return this._font; }
set
{
var parts = value.Split(',');
foreach (var part in parts)
{
//This deals with setting font size. Looks for either <number>px or <number>pt style="font: bold 16px/normal 'trebuchet ms', verdana, sans-serif;"
Regex rx = new Regex(@"(\d+)+(?=pt|px)");
var res = rx.Match(part);
if (res.Success)
{
int fontSize = 10;
int.TryParse(res.Value, out fontSize);
this.FontSize = new SvgUnit((float)fontSize);
}
//this assumes "bold" has spaces around it. e.g.: style="font: bold 16px/normal
rx = new Regex(@"\sbold\s");
res = rx.Match(part);
if (res.Success)
{
this.FontWeight = SvgFontWeight.bold;
}
}
var font = ValidateFontFamily(value);
this._fontFamily = font;
this._font = font; //not sure this is used?
this.IsPathDirty = true;
}
}
/// <summary> /// <summary>
/// Gets or sets the fill. /// Gets or sets the fill.
/// </summary> /// </summary>
...@@ -287,15 +208,6 @@ namespace Svg ...@@ -287,15 +208,6 @@ namespace Svg
get { return this.Path.GetBounds(); } get { return this.Path.GetBounds(); }
} }
static private RectangleF MeasureString(SvgRenderer renderer, string text, Font font)
{
GraphicsPath p = new GraphicsPath();
p.AddString(text, font.FontFamily, 0, font.Size, new PointF(0.0f, 0.0f), StringFormat.GenericTypographic);
p.Transform(renderer.Transform);
return p.GetBounds();
}
private static string ValidateFontFamily(string fontFamilyList) private static string ValidateFontFamily(string fontFamilyList)
{ {
// Split font family list on "," and then trim start and end spaces and quotes. // Split font family list on "," and then trim start and end spaces and quotes.
...@@ -388,12 +300,14 @@ namespace Svg ...@@ -388,12 +300,14 @@ namespace Svg
stringBounds = _stringMeasure.MeasureString(PrepareText(node.Content, stringBounds = _stringMeasure.MeasureString(PrepareText(node.Content,
i > 0 && nodes[i - 1] is SvgTextBase, i > 0 && nodes[i - 1] is SvgTextBase,
i < nodes.Count - 1 && nodes[i + 1] is SvgTextBase), font); i < nodes.Count - 1 && nodes[i + 1] is SvgTextBase), font);
result.Nodes.Add(new NodeBounds() { Bounds = stringBounds, Node = node, xOffset = totalWidth });
} }
else else
{ {
stringBounds = innerText.GetTextBounds().Bounds; stringBounds = innerText.GetTextBounds().Bounds;
}
result.Nodes.Add(new NodeBounds() { Bounds = stringBounds, Node = node, xOffset = totalWidth }); result.Nodes.Add(new NodeBounds() { Bounds = stringBounds, Node = node, xOffset = totalWidth });
totalWidth += innerText.Dx.ToDeviceValue(this);
}
totalHeight = Math.Max(totalHeight, stringBounds.Height); totalHeight = Math.Max(totalHeight, stringBounds.Height);
totalWidth += stringBounds.Width; totalWidth += stringBounds.Width;
} }
...@@ -446,6 +360,7 @@ namespace Svg ...@@ -446,6 +360,7 @@ namespace Svg
} }
NodeBounds data; NodeBounds data;
var yCummOffset = 0.0f;
for (var i = 0; i < boundsData.Nodes.Count; i++) for (var i = 0; i < boundsData.Nodes.Count; i++)
{ {
data = boundsData.Nodes[i]; data = boundsData.Nodes[i];
...@@ -460,7 +375,8 @@ namespace Svg ...@@ -460,7 +375,8 @@ namespace Svg
else else
{ {
innerText._calcX = x + data.xOffset; innerText._calcX = x + data.xOffset;
innerText._calcY = y; innerText._calcY = y + yCummOffset;
yCummOffset += innerText.Dy.ToDeviceValue(this);
} }
} }
...@@ -497,20 +413,63 @@ namespace Svg ...@@ -497,20 +413,63 @@ namespace Svg
/// <returns></returns> /// <returns></returns>
internal Font GetFont() internal Font GetFont()
{ {
var parent = this.Parent as SvgTextBase; var parentList = this.ParentsAndSelf.OfType<SvgVisualElement>().ToList();
Font parentFont = null;
if (parent != null) parentFont = parent.GetFont(); // Get the font-size
float fontSize;
var fontSizeUnit = GetInheritedFontSize();
if (fontSizeUnit == SvgUnit.None)
{
fontSize = 1.0f;
}
else
{
fontSize = fontSizeUnit.ToDeviceValue(this);
}
float fontSize = this.FontSize.ToDeviceValue(this); var fontStyle = System.Drawing.FontStyle.Regular;
if (fontSize == 0.0f)
// Get the font-weight
var weightElement = (from e in parentList where e.FontWeight != SvgFontWeight.inherit select e).FirstOrDefault();
if (weightElement != null)
{
switch (weightElement.FontWeight)
{
case SvgFontWeight.bold:
case SvgFontWeight.bolder:
case SvgFontWeight.w700:
case SvgFontWeight.w800:
case SvgFontWeight.w900:
fontStyle |= System.Drawing.FontStyle.Bold;
break;
}
}
// Get the font-style
var styleElement = (from e in parentList where e.FontStyle != SvgFontStyle.inherit select e).FirstOrDefault();
if (styleElement != null)
{
switch (styleElement.FontStyle)
{
case SvgFontStyle.italic:
case SvgFontStyle.oblique:
fontStyle |= System.Drawing.FontStyle.Italic;
break;
}
}
// Get the font-family
var fontFamilyElement = (from e in parentList where e.FontFamily != null && e.FontFamily != "inherit" select e).FirstOrDefault();
string family;
if (fontFamilyElement == null)
{
family = DefaultFontFamily;
}
else
{ {
fontSize = (parentFont == null ? 1.0f : parentFont.Size); family = ValidateFontFamily(fontFamilyElement.FontFamily) ?? DefaultFontFamily;
fontSize = (fontSize == 0.0f ? 1.0f : fontSize);
} }
var fontWeight = ((_fontWeight == SvgFontWeight.inherit && parentFont != null && parentFont.Bold) || _fontWeight == SvgFontWeight.bold ? return new Font(family, fontSize, fontStyle, GraphicsUnit.Pixel);
FontStyle.Bold : FontStyle.Regular);
var family = _fontFamily ?? (parentFont == null ? DefaultFontFamily : parentFont.FontFamily.Name);
return new Font(family, fontSize, fontWeight, GraphicsUnit.Pixel);
} }
/// <summary> /// <summary>
......
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