PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Underlined and striked out text with XPageDirection.Upwards
https://forum.pdfsharp.net/viewtopic.php?f=3&t=1041
Page 1 of 1

Author:  baSSiLL [ Tue Feb 02, 2010 11:16 am ]
Post subject:  Underlined and striked out text with XPageDirection.Upwards

PdfSharp version 1.31.

When drawing text to PDF page (using XGraphics created by XGraphics.FromPdfPage), and page direction is XPageDirection.Upwards, the XFontStyle.Underline and XFontStyle.Strikeout styles are not rendered correctly. Corresponding lines are misplaced and look interchanged: strikeout is below baseline, and underline goes through the middle of the letters.

I propose a patch to the PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer.DrawString that fixes the bug. Note that line numbers may slightly differ because we've ported PdfSharp sources to .NET 1.1.

Code:
--- C:/TMP/XGraphicsPdfRenderer.cs-revBASE.svn000.tmp.cs   Вт фев  2 14:02:16 2010
+++ D:/projects-svn/cis-forms.net/PdfSharp/PdfSharp.Drawing.Pdf/XGraphicsPdfRenderer.cs   Вт фев  2 13:16:37 2010
@@ -504,7 +504,7 @@
         // TODO: emulate bold by thicker outline
       }
 
-      if (italic && !descriptor.IsBoldFace)
+      if (italic && !descriptor.IsItalicFace)
       {
         // TODO: emulate italic by shearing transformation
       }
@@ -550,14 +550,20 @@
       {
         double underlinePosition = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlinePosition / font.cellSpace;
         double underlineThickness = lineSpace * realizedFont.FontDescriptor.descriptor.UnderlineThickness / font.cellSpace;
-        DrawRectangle(null, brush, x, y - underlinePosition, width, underlineThickness);
+        double underlineRectY = Gfx.PageDirection == XPageDirection.Downwards
+          ? y - underlinePosition
+          : y + underlinePosition - underlineThickness;
+        DrawRectangle(null, brush, x, underlineRectY, width, underlineThickness);
       }
 
       if (strikeout)
       {
         double strikeoutPosition = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutPosition / font.cellSpace;
         double strikeoutSize = lineSpace * realizedFont.FontDescriptor.descriptor.StrikeoutSize / font.cellSpace;
-        DrawRectangle(null, brush, x, y - strikeoutPosition - strikeoutSize, width, strikeoutSize);
+        double strikeoutRectY = Gfx.PageDirection == XPageDirection.Downwards
+          ? y - strikeoutPosition
+          : y + strikeoutPosition - strikeoutSize;
+        DrawRectangle(null, brush, x, strikeoutRectY, width, strikeoutSize);
       }
     }


PS. It may be useful to allow attachments in this forum. I've tried with .diff and .txt extensions with no success.

Author:  Thomas Hoevel [ Wed Feb 03, 2010 9:22 am ]
Post subject:  Re: Underlined and striked out text with XPageDirection.Upwards

baSSiLL wrote:
PS. It may be useful to allow attachments in this forum. I've tried with .diff and .txt extensions with no success.


Attachments are allowed (images and archives).

Attachments:
File comment: I'm an attachment
Hello.zip [129 Bytes]
Downloaded 585 times

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/