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
68425a1c
Commit
68425a1c
authored
Jan 07, 2014
by
Tebjan Halm
Browse files
Merge pull request #40 from Rob1080/StyleFonts
Fix for text when using Style="font:.." format. e.g. style="font: bold ...
parents
4cc1d9e7
efe165d4
Changes
1
Show whitespace changes
Inline
Side-by-side
Source/Text/SvgText.cs
View file @
68425a1c
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Text
;
using
System.Text
;
using
System.Text.RegularExpressions
;
using
System.ComponentModel
;
using
System.ComponentModel
;
using
System.Drawing
;
using
System.Drawing
;
using
System.Drawing.Drawing2D
;
using
System.Drawing.Drawing2D
;
...
@@ -172,7 +173,35 @@ namespace Svg
...
@@ -172,7 +173,35 @@ namespace Svg
public
virtual
string
Font
public
virtual
string
Font
{
{
get
{
return
this
.
_font
;
}
get
{
return
this
.
_font
;
}
set
{
this
.
_font
=
value
;
this
.
IsPathDirty
=
true
;
}
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>
...
@@ -289,7 +318,8 @@ namespace Svg
...
@@ -289,7 +318,8 @@ namespace Svg
var
families
=
System
.
Drawing
.
FontFamily
.
Families
;
var
families
=
System
.
Drawing
.
FontFamily
.
Families
;
// Find a the first font that exists in the list of installed font 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
)))
//styles from IE get sent through as lowercase.
foreach
(
var
f
in
fontParts
.
Where
(
f
=>
families
.
Any
(
family
=>
family
.
Name
.
ToLower
()
==
f
.
ToLower
())))
{
{
return
f
;
return
f
;
}
}
...
...
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