Skip to content

Commit acf3c18

Browse files
authored
Merge pull request #28 from paulushub/master
Code improvements to remove build warnings
2 parents 8e4e68c + 9c26d37 commit acf3c18

File tree

5 files changed

+32
-9
lines changed

5 files changed

+32
-9
lines changed

Source/SVGImage/SVG/SVGRender.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,11 +460,11 @@ internal DrawingGroup LoadGroup(IList<Shape> elements, Rect? viewBox, bool isSwi
460460
if (shape is PathShape)
461461
{
462462
PathShape r = shape as PathShape;
463-
PathFigure p = null;
463+
// PathFigure p = null;
464464
Point lastPoint = new Point(0, 0);
465465

466-
PathShape.CurveTo lastc = null;
467-
PathShape.QuadraticCurveTo lastq = null;
466+
// PathShape.CurveTo lastc = null;
467+
// PathShape.QuadraticCurveTo lastq = null;
468468
Point lastcirPoint = new Point(0, 0);
469469
PathGeometry path = PathGeometry.CreateFromGeometry(PathGeometry.Parse(r.Data));
470470
//PathGeometry path = new PathGeometry();

Source/SVGImage/SVG/SVGTags.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace SVGImage.SVG
22
{
3-
class SVGTags
3+
static class SVGTags
44
{
55
public const string sSvg = "svg";
66
public const string sNsSvg = "http://www.w3.org/2000/svg";

Source/SVGImage/SVG/ShapeUtil.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
namespace SVGImage.SVG
99
{
10-
public class ShapeUtil
10+
public static class ShapeUtil
1111
{
1212
public static Transform ParseTransform(string value)
1313
{

Source/SVGImage/SVG/Shapes/ImageShape.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System;
22
using System.IO;
3+
using System.Xml;
4+
using System.Diagnostics;
5+
36
using System.Windows.Media;
47
using System.Windows.Media.Imaging;
5-
using System.Xml;
68

79
namespace SVGImage.SVG.Shapes
810
{
@@ -44,8 +46,10 @@ public ImageShape(SVG svg, XmlNode node) : base(svg, node)
4446
b.EndInit();
4547
this.ImageSource = b;
4648
}
47-
catch(Exception ex)
48-
{ }
49+
catch (Exception ex)
50+
{
51+
Trace.TraceError(ex.Message);
52+
}
4953
}
5054
}
5155
}

Source/SVGImage/SVG/TextRender.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
using System.Collections.Generic;
22
using System.Windows.Media;
33
using System.Windows;
4+
using System.Reflection;
45

56
namespace SVGImage.SVG
67
{
7-
class TextRender
8+
static class TextRender
89
{
10+
private static int dpiX = 0;
11+
private static int dpiY = 0;
12+
913
static public GeometryGroup BuildTextGeometry(TextShape shape)
1014
{
1115
return BuildGlyphRun(shape, 0, 0);
@@ -76,6 +80,15 @@ static Geometry BuildGlyphRun(TextStyle textStyle, string text, double x, double
7680
if (string.IsNullOrEmpty(text))
7781
return new GeometryGroup();
7882

83+
if (dpiX == 0 || dpiY == 0)
84+
{
85+
var sysPara = typeof(SystemParameters);
86+
var dpiXProperty = sysPara.GetProperty("DpiX", BindingFlags.NonPublic | BindingFlags.Static);
87+
var dpiYProperty = sysPara.GetProperty("Dpi", BindingFlags.NonPublic | BindingFlags.Static);
88+
89+
dpiX = (int)dpiXProperty.GetValue(null, null);
90+
dpiY = (int)dpiYProperty.GetValue(null, null);
91+
}
7992
double fontSize = textStyle.FontSize;
8093
GlyphRun glyphs = null;
8194
Typeface font = new Typeface(new FontFamily(textStyle.FontFamily),
@@ -87,7 +100,13 @@ static Geometry BuildGlyphRun(TextStyle textStyle, string text, double x, double
87100
double baseline = y;
88101
if (font.TryGetGlyphTypeface(out glyphFace))
89102
{
103+
#if DOTNET40 || DOTNET45 || DOTNET46
90104
glyphs = new GlyphRun();
105+
#else
106+
var dpiScale = new DpiScale(dpiX, dpiY);
107+
108+
glyphs = new GlyphRun((float)dpiScale.PixelsPerDip);
109+
#endif
91110
((System.ComponentModel.ISupportInitialize)glyphs).BeginInit();
92111
glyphs.GlyphTypeface = glyphFace;
93112
glyphs.FontRenderingEmSize = fontSize;

0 commit comments

Comments
 (0)