Menu

#170 [wxPdfDocument] Bug in wxPdfDC::DrawRotatedText

Subversion_TRUNK
closed-fixed
wxpdfdoc (23)
5
2015-11-23
2015-11-04
No

When drawing rotated text using wxPdfDC::DrawRotatedText, the text is rotated about the wrong point.

With wxDC::DrawRotatedText, the coordinates specified are to position the top-left corner of the text, and the text is rotated around that point. For wxPdfDocument, the coordinates specified are to position the middle-left of the text, and the text is rotated around that point.

wxPdfDC translates the coordinates for the differences in positioning of the text and forwards it to wxPdfDocument::RotatedText, but it cannot specify an alternate point for the center of the rotation.

To patch my copy and to not change semantics of wxPdfDocument, I added a new function wxPdfDocument::DrawRotated2, taking two coordinates instead of one, the text position and the point to rotate the text around.

My changes below as unified diffs:

Index: pdfdocument.h
===================================================================
--- pdfdocument.h   (revision 3182)
+++ pdfdocument.h   (working copy)
@@ -1312,6 +1312,17 @@
   */
   virtual void RotatedText(double x, double y, const wxString& txt, double angle);

+  /// Prints a rotated text string
+  /**
+  * \param textX Abscissa of the origin
+  * \param textY Ordinate of the origin
+  * \param rotationX: abscissa of the rotation center.
+  * \param rotationY: ordinate of the rotation center.
+  * \param txt String to print
+  * \param angle: angle in degrees.
+  */
+  virtual void RotatedText2(double textX, double textY, double rotationX, double rotationY, const wxString& txt, double angle);
+
   /// Whenever a page break condition is met,
   /**
   * Whenever a page break condition is met, the method is called, and the break is issued or not
Index: pdfdc29.inc
===================================================================
--- pdfdc29.inc (revision 3182)
+++ pdfdc29.inc (working copy)
@@ -939,6 +939,8 @@
   }
   wxFont old = m_font;

+  wxCoord originalY = y;
+
   wxPdfFontDescription desc = m_pdfDocument->GetFontDescription();
   int height, descent;
   CalculateFontMetrics(&desc, fontToUse->GetPointSize(), &height, NULL, &descent, NULL);
@@ -949,7 +951,7 @@

   m_pdfDocument->SetTextColour(m_textForegroundColour.Red(), m_textForegroundColour.Green(), m_textForegroundColour.Blue());
   m_pdfDocument->SetFontSize(ScaleFontSizeToPdf(fontToUse->GetPointSize()));
-  m_pdfDocument->RotatedText(ScaleLogicalToPdfX(x), ScaleLogicalToPdfY(y), text, angle);
+  m_pdfDocument->RotatedText2(ScaleLogicalToPdfX(x), ScaleLogicalToPdfY(y), ScaleLogicalToPdfX(x), ScaleLogicalToPdfY(originalY), text, angle);
   SetFont(old);
 }
Index: pdfdocument.cpp
===================================================================
--- pdfdocument.cpp (revision 3182)
+++ pdfdocument.cpp (working copy)
@@ -978,6 +978,23 @@
   }
 }

+void
+wxPdfDocument::RotatedText2(double textX, double textY, double rotationX, double rotationY, const wxString& txt, double angle)
+{
+  // Text rotated around its origin
+  if (angle == 0)
+  {
+    Text(textX, textY, txt);
+  }
+  else
+  {
+    StartTransform();
+    Rotate(angle, rotationX, rotationY);
+    Text(textX, textY, txt);
+    StopTransform();
+  }
+}
+
 bool
 wxPdfDocument::AcceptPageBreak()
 {

Discussion

  • Ulrich Telle

    Ulrich Telle - 2015-11-23

    Fixed in wxCode SVN.

     
  • Ulrich Telle

    Ulrich Telle - 2015-11-23
    • status: open --> closed-fixed
    • Group: CVS_HEAD --> Subversion_TRUNK
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.