Announcement

Collapse
No announcement yet.

Justify text in Paragragh Object

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Justify text in Paragragh Object

    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.

  • #2
    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});
    Demo apz is attached below.

    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.
    Attached Files

    Comment


    • #3
      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);
      Closer reading of the documentation set out in the manual (under the RichText.SetParagraphFormat section) elucidates the issue somewhat:

      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.
      As far as I know, Rich Edit controls earlier than Rich Edit 3.0 would actually be pre-WinXP, so this is kind of confusing. However, to successfully display 'justified' text, there is a need to grab the RTO WindowHandle and apply typography options by calling the user32.dll. That's why the additional code (as shown in previous post above) is needed.

      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
      Page On Show or Button On Click (function may be called from any event in which the RTO is already drawn)
      Code:
      i = 1; [I]-- whereby i equals index number of RichText object/s.[/I]
      RTO_Justify()
      Demo apz attached below.
      Attached Files

      Comment

      Working...
      X