Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ImportedProjects
SVG
Commits
57ea0472
Commit
57ea0472
authored
Sep 11, 2013
by
samjudson
Browse files
Update SvgText.cs
Added support for multiple comma separated font lists, CSS style.
parent
a45d151c
Changes
1
Show whitespace changes
Inline
Side-by-side
Source/Text/SvgText.cs
View file @
57ea0472
...
@@ -27,6 +27,8 @@ namespace Svg
...
@@ -27,6 +27,8 @@ namespace Svg
private
GraphicsPath
_path
;
private
GraphicsPath
_path
;
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"
;
/// <summary>
/// <summary>
/// Initializes the <see cref="SvgText"/> class.
/// Initializes the <see cref="SvgText"/> class.
/// </summary>
/// </summary>
...
@@ -42,7 +44,7 @@ namespace Svg
...
@@ -42,7 +44,7 @@ namespace Svg
/// </summary>
/// </summary>
public
SvgText
()
public
SvgText
()
{
{
this
.
_fontFamily
=
"Times New Roman"
;
this
.
_fontFamily
=
DefaultFontFamily
;
this
.
_fontSize
=
new
SvgUnit
(
0.0f
);
this
.
_fontSize
=
new
SvgUnit
(
0.0f
);
}
}
...
@@ -124,7 +126,11 @@ namespace Svg
...
@@ -124,7 +126,11 @@ namespace Svg
public
virtual
string
FontFamily
public
virtual
string
FontFamily
{
{
get
{
return
this
.
_fontFamily
;
}
get
{
return
this
.
_fontFamily
;
}
set
{
this
.
_fontFamily
=
value
;
this
.
IsPathDirty
=
true
;
}
set
{
this
.
_fontFamily
=
ValidateFontFamily
(
value
);
this
.
IsPathDirty
=
true
;
}
}
}
/// <summary>
/// <summary>
...
@@ -232,7 +238,7 @@ namespace Svg
...
@@ -232,7 +238,7 @@ namespace Svg
}
}
FontStyle
fontWeight
=
(
this
.
FontWeight
==
SvgFontWeight
.
bold
?
FontStyle
.
Bold
:
FontStyle
.
Regular
);
FontStyle
fontWeight
=
(
this
.
FontWeight
==
SvgFontWeight
.
bold
?
FontStyle
.
Bold
:
FontStyle
.
Regular
);
Font
font
=
new
Font
(
this
.
_fontFamily
.
Split
(
new
[]
{
','
})[
0
]
,
fontSize
,
fontWeight
,
GraphicsUnit
.
Pixel
);
Font
font
=
new
Font
(
this
.
_fontFamily
,
fontSize
,
fontWeight
,
GraphicsUnit
.
Pixel
);
_path
=
new
GraphicsPath
();
_path
=
new
GraphicsPath
();
_path
.
StartFigure
();
_path
.
StartFigure
();
...
@@ -261,6 +267,21 @@ namespace Svg
...
@@ -261,6 +267,21 @@ namespace Svg
}
}
}
}
private
static
string
ValidateFontFamily
(
string
fontFamilyList
)
{
// Split font family list on "," and then trim start and end spaces and quotes.
var
fontParts
=
fontFamilyList
.
Split
(
new
[]
{
','
}).
Select
(
fontName
=>
fontName
.
Trim
(
new
[]
{
'"'
,
' '
}));
var
families
=
System
.
Drawing
.
FontFamily
.
Families
;
// Find a the first font that exists in the list of installed font families.
foreach
(
var
f
in
fontParts
.
Where
(
f
=>
families
.
Any
(
family
=>
family
.
Name
==
f
)))
{
return
f
;
}
// No valid font family found from the list requested.
return
DefaultFontFamily
;
}
private
void
DrawString
(
GraphicsPath
path
,
SvgUnit
x
,
SvgUnit
y
,
SvgUnit
dx
,
SvgUnit
dy
,
Font
font
,
float
fontSize
,
string
text
)
private
void
DrawString
(
GraphicsPath
path
,
SvgUnit
x
,
SvgUnit
y
,
SvgUnit
dx
,
SvgUnit
dy
,
Font
font
,
float
fontSize
,
string
text
)
{
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment