Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
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
b044459f
Commit
b044459f
authored
13 years ago
by
Tebjan Halm
Browse files
Options
Download
Email Patches
Plain Diff
* correct text alignment on base line
* added precise MeasureString method
parent
9d37b566
master
netstandard2
nuget2.4.2
nuget2.4.1
nuget2.4
nuget2.3
nuget2.2.2
nuget2.2.1
nuget1.7
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Source/SvgRenderer.cs
+15
-0
Source/SvgRenderer.cs
Source/Text/SvgText.cs
+6
-6
Source/Text/SvgText.cs
Source/Text/SvgTextAnchor.cs
+2
-0
Source/Text/SvgTextAnchor.cs
with
23 additions
and
6 deletions
+23
-6
Source/SvgRenderer.cs
+
15
-
0
View file @
b044459f
...
...
@@ -132,5 +132,20 @@ namespace Svg
{
this
.
_innerGraphics
.
Dispose
();
}
public
SizeF
MeasureString
(
string
text
,
Font
font
)
{
var
ff
=
font
.
FontFamily
;
float
lineSpace
=
ff
.
GetLineSpacing
(
font
.
Style
);
float
ascent
=
ff
.
GetCellAscent
(
font
.
Style
);
float
baseline
=
font
.
GetHeight
(
this
.
_innerGraphics
)
*
ascent
/
lineSpace
;
StringFormat
format
=
StringFormat
.
GenericTypographic
;
format
.
SetMeasurableCharacterRanges
(
new
CharacterRange
[]{
new
CharacterRange
(
0
,
text
.
Length
)});
Region
[]
r
=
this
.
_innerGraphics
.
MeasureCharacterRanges
(
text
,
font
,
new
Rectangle
(
0
,
0
,
1000
,
1000
),
format
);
RectangleF
rect
=
r
[
0
].
GetBounds
(
this
.
_innerGraphics
);
return
new
SizeF
(
rect
.
Width
,
baseline
);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Source/Text/SvgText.cs
+
6
-
6
View file @
b044459f
...
...
@@ -191,6 +191,7 @@ namespace Svg
{
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
();
}
...
...
@@ -211,23 +212,22 @@ namespace Svg
{
fontSize
=
1.0f
;
}
RectangleF
stringBounds
;
PointF
location
=
PointF
.
Empty
;
Font
font
=
new
Font
(
this
.
_fontFamily
,
fontSize
,
FontStyle
.
Regular
,
GraphicsUnit
.
Pixel
);
SizeF
stringBounds
=
_stringMeasure
.
MeasureString
(
this
.
Text
,
font
);
// Minus FontSize because the x/y coords mark the bottom left, not bottom top.
switch
(
this
.
TextAnchor
)
{
case
SvgTextAnchor
.
Start
:
location
=
new
PointF
(
this
.
X
.
ToDeviceValue
(
this
),
this
.
Y
.
ToDeviceValue
(
this
,
true
)
-
this
.
_fontSize
);
location
=
new
PointF
(
this
.
X
.
ToDeviceValue
(
this
),
this
.
Y
.
ToDeviceValue
(
this
,
true
)
-
stringBounds
.
Height
);
break
;
case
SvgTextAnchor
.
Middle
:
stringBounds
=
SvgText
.
MeasureString
(
_stringMeasure
,
this
.
Text
,
font
);
location
=
new
PointF
(
this
.
X
.
ToDeviceValue
(
this
)
-
(
stringBounds
.
Width
/
2
),
this
.
Y
.
ToDeviceValue
(
this
,
true
)
-
this
.
_fontSize
);
location
=
new
PointF
(
this
.
X
.
ToDeviceValue
(
this
)
-
(
stringBounds
.
Width
/
2
),
this
.
Y
.
ToDeviceValue
(
this
,
true
)
-
stringBounds
.
Height
);
break
;
case
SvgTextAnchor
.
End
:
stringBounds
=
SvgText
.
MeasureString
(
_stringMeasure
,
this
.
Text
,
font
);
location
=
new
PointF
(
this
.
X
.
ToDeviceValue
(
this
)
-
stringBounds
.
Width
,
this
.
Y
.
ToDeviceValue
(
this
,
true
)
-
this
.
_fontSize
);
location
=
new
PointF
(
this
.
X
.
ToDeviceValue
(
this
)
-
stringBounds
.
Width
,
this
.
Y
.
ToDeviceValue
(
this
,
true
)
-
stringBounds
.
Height
);
break
;
}
...
...
This diff is collapsed.
Click to expand it.
Source/Text/SvgTextAnchor.cs
+
2
-
0
View file @
b044459f
...
...
@@ -2,12 +2,14 @@
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.ComponentModel
;
namespace
Svg
{
/// <summary>
/// Text anchor is used to align (start-, middle- or end-alignment) a string of text relative to a given point.
/// </summary>
[
TypeConverter
(
typeof
(
SvgTextAnchorConverter
))]
public
enum
SvgTextAnchor
{
/// <summary>
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help