Skip to content

Commit 09dc8ef

Browse files
committed
D2DGraphics: fixed MeasureText() is not correct
1 parent 53b768e commit 09dc8ef

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Source/DXControl/Graphics/D2DGraphics.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ public SizeF MeasureText(string text, string fontFamilyName, float fontSize, Siz
394394
{
395395
// fix DPI
396396
var dpiScale = textDpi / 96.0f;
397-
fontSize += fontSize * dpiScale;
397+
fontSize = (fontSize + dpiScale) * dpiScale;
398398

399399
// format text
400400
var fontWeight = isBold

Source/DXControl/Graphics/GdipGraphics.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,11 @@ public SizeF MeasureText(string text, string fontFamilyName, float fontSize, flo
241241

242242
public SizeF MeasureText(string text, string fontFamilyName, float fontSize, SizeF size, float textDpi = 96, bool isBold = false, bool isItalic = false)
243243
{
244-
var dpiFactor = textDpi / 96.0f;
245-
fontSize = (fontSize + dpiFactor) * dpiFactor;
244+
// fix DPI
245+
var dpiScale = textDpi / 96.0f;
246+
fontSize = (fontSize + dpiScale) * dpiScale;
246247

248+
// format text
247249
var style = FontStyle.Regular;
248250
if (isBold) style |= FontStyle.Bold;
249251
if (isItalic) style |= FontStyle.Italic;

0 commit comments

Comments
 (0)