Is there an easy way to Justify text in a Paragraph Object. I need my text to fit in a paragraph box like a newspaper clipping.
Announcement
Collapse
No announcement yet.
Justify text in Paragragh Object
Collapse
X
-
I don't think it can be done via the Paragraph object. But if you use the RichText object instead, you can justify the text with typography options via the Windows user32.dll, like this:
Code:local WM_USER = 0x400; local EM_SETTYPOGRAPHYOPTIONS = WM_USER + 202; local TO_ADVANCEDTYPOGRAPHY = 1; local hWnd = RichText.GetProperties("RichText1").WindowHandle; local parameters = hWnd..","..EM_SETTYPOGRAPHYOPTIONS..","..TO_ADVANCEDTYPOGRAPHY..","..TO_ADVANCEDTYPOGRAPHY DLL.CallFunction("user32.dll", "SendMessageA", parameters, DLL_RETURN_TYPE_LONG, DLL_CALL_STDCALL); RichText.SetParagraphFormat("RichText1", {Alignment = PFA_JUSTIFY});
Alternatively, you could use the Web object to load a local HTML file which takes advantage of HTML/CSS formatting tags to display justified text. And which can also blend the Web object in with the rest of your page. Demo apz also attached.
- Likes 1
-
Generally speaking, the axiom, "If it ain't broke, don't fix it" is a good rule-of-thumb. But for the sake of clarity (and for others wanting to display 'justified' text on the RichText object), it's probably prudent to point out something here which may not be immediately obvious.
There's been at least a couple of threads in past years, in which the question has been asked, "If I want to display justified text in the RTO, then why can't I just do something like this?"
Code:tbFormat = {}; tbFormat.Alignment = PFA_JUSTIFY; RichText.SetParagraphFormat("RichText1", tbFormat);
PFA_JUSTIFY (4) - Justify paragraphs (Rich Edit 2.0). This value is included for compatibility with TOM interfaces; rich edit controls earlier than Rich Edit 3.0 display the text aligned with the left margin.
I'm really not too sure who first developed that codeblock. But regardless, I thought it worth mentioning that the whole codeblock can be expressed more succinctly and utilized more efficiently - by referencing parameter values in the DLL call procedure directly, and then wrapping the whole thing as a function that sits in Globals. Call the function from any event in which the RTO has already been drawn. (Nb. In the example below, the RTO index number should be referenced via the 'i' variable):
Globals:
Code:function RTO_Justify() hWnd = RichText.GetProperties("RichText"..i).WindowHandle; DLL.CallFunction("user32.dll", "SendMessageA", hWnd..",".. 0x400+202 ..",".. 1 ..",".. 1, 1, 1); RichText.SetParagraphFormat("RichText"..i, {Alignment=4}); end
Code:i = 1; [I]-- whereby i equals index number of RichText object/s.[/I] RTO_Justify()
- Likes 1
Comment
Comment