Hello zyx, PoDoFo devs, an update on the PdfPainter situation: a rework of the PdfPainter has been carried out to address some reviews/concerns. It follows the changes and design notes: - The previously described path "context" has been renamed/moved to a PdfPainterPath[1] class, now representing an external path in construction. The class allows to retrieve a string view of the path currently being built, and can be drawn/clipped with PdfPainter::DrawPath/ClipPath; - A base "interface" like PdfContentStreamOperators[2] class has been introduced offering a low level content stream manipulation layer to be used by power users. PdfPainter implements all the methods of the class privately: such low level functionalities can be retrieved by casting the painter instance to PdfContentStreamOperators. It is worth to add that such functionalities are still partially validated by the internal state of the painter; - PdfPainter and PdfPainterPath still offer an easy to use high level interface for Pdf drawing operations, and now even more closely match the API design of .NET Graphics and GraphicsPath class (to zyx for reference: NET Graphics is really a MS official wrapper around HDC/GDI Windows API); - The text "context" has been renamed to PdfPainterTextObject, and the PdfPainter::Text instance renamed to TextObject, to reflect the PDF specification naming. This remains an interface to manually handle BT .. ET stacking and add continuous text. The high level text API to draw text remains PdfPainter::DrawText like functions.
I also privately received some feedback that relates to writing proper glyph positioning: a status describing the painter being constructing glyphs array ("[ gliphs1 delta glyps2 ... ] TJ") and glyph arrays writing primitives were added. These should help in the future to the introduction of text shaping with HarfBuzz[3]. It follows an example of use of the updated API: PdfPainter painter; painter.SetCanvas(page); painter.TextState.SetFont(font, 15); painter.DrawText("Test2", 100, 600, PdfDrawTextStyle::StrikeOut); painter.TextObject.Begin(); painter.TextObject.MoveTo(100, 500); painter.TextObject.AddText("Test"); painter.TextObject.End(); painter.GraphicsState.SetLineWidth(1); PdfPainterPath path; path.MoveTo(20, 20); path.AddArcTo(150, 20, 150, 70, 50); path.AddLineTo(150, 120); painter.DrawPath(path, PdfPathDrawMode::Stroke); path.Reset(); path.MoveTo(40, 40); path.AddLineTo(100, 40); path.AddLineTo(70, 80); path.AddLineTo(40, 40); path.AddCircle(200, 200, 60); painter.DrawPath(path, PdfPathDrawMode::Fill); painter.Save(); const double SquareSize = 6; painter.GraphicsState.SetLineWidth(0.6); painter.DrawRectangle(150 - SquareSize / 2, 70 - SquareSize / 2, SquareSize, SquareSize); painter.GraphicsState.SetLineWidth(0); painter.DrawLine(150, 70 - SquareSize / 2, 150, 70 + SquareSize / 2); painter.DrawLine(150 - SquareSize / 2, 70, 150 + SquareSize / 2, 70); painter.Restore(); Here it follows an example of use of the low level interface: auto& operators = static_cast<PdfContentStreamOperators&>(painter); painter.TextObject.Begin(); painter.TextObject.MoveTo(100, 500); // Some low level operations operators.TJ_Operator_Begin(); operators.TJ_Operator_Glyphs("W", false); operators.TJ_Operator_Delta(-500); operators.TJ_Operator_Glyphs("orld", false); operators.TJ_Operator_End(); painter.TextObject.End(); The goal of the PdfPainter revamp isn't being a 100% complete drawing API, but put a more robust foundation for growing in the future releases. If you have any further comment/review (can be as simple as suggesting better names for classes/members), please don't be shy to reply publicly: this makes the development process more transparent and motivates me in replying. As soon as there are no concerns that require immediate modifications, we can freeze the API and complete few more bugfixes heading for a 0.10 release. Cheers, Francesco [1] https://github.com/podofo/podofo/blob/master/src/podofo/main/PdfPainterPath.h [2] https://github.com/podofo/podofo/blob/master/src/podofo/main/PdfContentStreamOperators.h [3] https://github.com/harfbuzz/harfbuzz _______________________________________________ Podofo-users mailing list Podofo-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/podofo-users