MonkeybreadSoftware Posted 17 hours ago Posted 17 hours ago Sometimes you may have a project where you need to output bidirectional text. If you output any of the following languages, you may need to think about how to handle the right to left direction: Arabic Aramaic Azeri Dhivehi/Maldivian Hebrew Kurdish (Sorani) Persian/Farsi Urdu When you use DynaPDF in FileMaker with MBS FileMaker Plugin, you can use the DynaPDF.SetBidiMode function to enable bidirectional mode and set it to RightToLeft layout. Of course you need to load a font with unicode code page to have it cover all the characters. The bidi algorithm makes sure you can mix left to right and right to left text within a text, but you still need to define whether the layout is left to right or right to left. We start with initializing DynaPDF: # Initialize DynaPDF if needed If [ MBS("DynaPDF.IsInitialized") ≠ 1 ] Perform Script [ “InitDynaPDF” ; Specified: From list ; Parameter: ] End If Then we create a document. # Clear current PDF document Set Variable [ $pdf ; Value: MBS("DynaPDF.New") ] # Add page Set Variable [ $r ; Value: MBS("DynaPDF.AppendPage"; $pdf) ] Next we enable the complex text feature for Windows. This will use the Uniscribe.dll from Microsoft to pre-process the unicode text if needed. For example in Arabic text you need different glyphs depending on whether a letter is on the beginning, the middle or the end of the word. Since DynaPDF only provides this for Windows, you would need to do this yourself or with some other library. Or maybe in the future we can add support for macOS and use Apple's libraries. Next we set the Bidirectional mode to enable the feature and to define the layout direction. # Enable complex layout (Windows only) Set Variable [ $r ; Value: MBS("DynaPDF.SetGStateFlags"; $pdf; "ComplexText") ] Set Variable [ $r ; Value: MBS("DynaPDF.SetBidiMode"; $pdf; "RightToLeft") ] Next we query page size for the rectangle, load a font and output text. When you skip the codepage parameter for the font, our plugin assumes unicode. We set the rectangle elf the text and call DynaPDF.WriteFText to draw some text. Since we allow page breaks, the plugin would start a new page if the rectangle is full and more text needs to be drawn. You can use DynaPDF.SetPageBreakExpression to have some expression run when the page is full and decide whether to make a new page or a new column or stop. # Write some text Set Variable [ $PageHeight ; Value: MBS("DynaPDF.GetPageHeight"; $pdf) ] Set Variable [ $PageWidth ; Value: MBS("DynaPDF.GetPageWidth"; $pdf) ] # Make sure to load a font containing characters Set Variable [ $r ; Value: MBS("DynaPDF.SetFont"; $pdf; "Arial"; 0; 10) ] # Set Variable [ $r ; Value: MBS("DynaPDF.SetFillColor"; $pdf; 0; 0; 0) ] Set Variable [ $r ; Value: MBS("DynaPDF.SetTextRect"; $pdf; 100; $pageHeight-100;$PageWidth-150; $pageHeight-200) ] # allow several pages Set Variable [ $r ; Value: MBS("DynaPDF.AllowPageBreak"; $pdf; 1) ] Set Variable [ $r ; Value: MBS("DynaPDF.WriteFText"; $pdf; "left"; WriteFText::InputText) ] After all text is written, we can cleanup by closing thew page and saving the document. # End page Set Variable [ $r ; Value: MBS("DynaPDF.EndPage"; $pdf) ] # Set title Set Variable [ $r ; Value: MBS("DynaPDF.SetDocInfo"; $pdf; "Title"; "Test PDF") ] # Render one page as Picture Set Variable [ $PDFData ; Value: MBS("DynaPDF.Save"; $pdf; "hello.pdf") ] Set Variable [ $r ; Value: MBS("DynaPDF.Release"; $pdf) ] # Put in Container Set Field [ WriteFText::PDF ; $PDFData ] If you need to output bidirectional text, please try these functions. You need MBS FileMaker Plugin 15.2 or newer and a recent DynaPDF version.
Recommended Posts