Announcement

Collapse
No announcement yet.

XPrint - How do I print Right to Left Text?

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

  • XPrint - How do I print Right to Left Text?

    I have never used Xprint up to now as most of my printing requirements are Right to Left.

    I have RTFM'd but I cannot find anything - is it possible?

  • #2
    I don't know there is a 'native' capability to do so using XPRINT, but you could always reverse the characaters of the string (STRREVERSE$) and XPRINT that.
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Wait a minute... did you mean right-justified?

      This has come up here before. IIRC the solution was to measure the text, subtract from the right margin to find the starting point, and print the string left-justified there.
      Michael Mattias
      Tal Systems (retired)
      Port Washington WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Michael - your first assumption was the right one - Good idea.

        Funnily enough I use STRREVERSE$ a lot in my normal work but for LATIN text

        (Later: Must use your second suggestion as well because the text starts on the RH side of the page so it is effectively Right Justified)

        Many thanks.
        Last edited by Robert Wallace; 19 Feb 2009, 11:46 AM. Reason: Re-read MCM's posts

        Comment


        • #5
          I was thinking mirror'ed text.

          SetLayout

          The SetLayout function changes the layout of a device context (DC).
          Code:
          DWORD SetLayout(
            HDC hdc,             // handle to DC
            DWORD dwLayout,      // layout options
          );
          • Parameters
            • hdc
              • [in] Handle to the DC.
            • dwLayout
              • [in] Specifies the DC layout. This parameter can be one or more of the following values. Value Meaning
                • LAYOUT_BITMAPORIENTATIONPRESERVED Disables any reflection during BitBlt and StretchBlt operations.
                • LAYOUT_RTL Sets the default horizontal layout to be right to left.
          • Return Values
            • If the function succeeds, it returns the previous layout of the DC.
            • If the function fails, it returns GDI_ERROR. To get extended error information, call GetLastError.
          • Remarks
            • The layout specifies the order in which text and graphics are revealed in a window or a device context. The default is left to right. The SetLayout function changes this to be right to left, which is the standard in Arabic and Hebrew cultures.

          I'm just not certain if that is what he was looking to do.
          Furcadia, an interesting online MMORPG in which you can create and program your own content.

          Comment


          • #6
            Colin,

            May be the answer but unfortunately I have never used DC's in any of my programs (except one but I don't actually put anything in it as it is required by a Win API function).

            Does it actually mirror everything AFTER the contents of a DC have been created or does it just lay down the contents Right to Left as you create them?

            A mirrored "ABCD" is different to a RTL "DCBA"

            (Later:
            I was thinking mirror'ed text
            I think I was misled by your first line - on second reading I don't think the function does mirror.)

            Bob
            Last edited by Robert Wallace; 19 Feb 2009, 01:49 PM.

            Comment


            • #7
              That setlayout thing might be just what the doctor ordered... when you combine it with...
              Syntax
              XPRINT GET DC TO hDC???

              Remarks
              If no host printer is currently attached, zero is returned. The DC handle may be used with various Windows API functions to perform specialized operations on the host printer page.
              You'd still have to hope that XPRINT PRINT TEXT (or whatever that command is) respects the current settings of the device context; or if it (quite reasonably and politely IMO) saves the current settings, does its thing, and restores the saved settings.

              If you can't find that info in the help file, you'll have to ask support.
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Apparently not, you're getting a copy of the DC with the statement:
                Code:
                #COMPILE EXE
                #DIM ALL
                
                #INCLUDE "win32api.inc"
                
                DECLARE FUNCTION SetLayout LIB "gdi32.dll" ALIAS "SetLayout" (BYVAL hdc AS DWORD, BYVAL dwLayout AS DWORD) AS DWORD
                %LAYOUT_BITMAPORIENTATIONPRESERVED = &H8
                
                FUNCTION PBMAIN () AS LONG
                LOCAL hDC AS DWORD, oldDir AS DWORD
                
                    XPRINT ATTACH DEFAULT
                    IF ERR = 0 AND LEN(XPRINT$) > 0 THEN
                        XPRINT COLOR RGB(225,225,255)
                        XPRINT GET DC TO hDC
                    ' prints on the left side of the page
                        XPRINT "This is your printer talking"
                        oldDir = SetLayout (hDC, %LAYOUT_BITMAPORIENTATIONPRESERVED)
                    ' also prints on the left side of the page
                        XPRINT "This is your printer talking"
                        XPRINT FORMFEED           ' Issue a formfeed
                        SetLayout hDC, oldDir
                        XPRINT CLOSE              ' Deselect the printer
                    END IF
                END FUNCTION
                Furcadia, an interesting online MMORPG in which you can create and program your own content.

                Comment


                • #9
                  Robert this might help
                  Code:
                    XPRINT TEXT SIZE thetext$ TO xx!,yy!
                    XPRINT GET CLIENT TO ww!,hh!   'according to xprint scale
                    XPRINT GET POS TO x!,y!        'current line info (column pos unimportant)
                     x!=(ww!-xx!)    'figure the starting pos for text
                     XPRINT SET POS (x!,y!)  'set the position 
                     XPRINT thetext$
                  Client Writeup for the CPA

                  buffs.proboards2.com

                  Links Page

                  Comment


                  • #10
                    Very many thanks - I think you have all given me enough to get started with XPRINT

                    Bob

                    Comment


                    • #11
                      I cannot do l what I want - RTL is possible as explained above but I have just found that the "XPRINT" command can only handle ASCII (not actually specified in the Help but xref's to LPRINT which is ASCII only - I suspect that the Help really meant ANSI).

                      It seems that the only quick & flexible solution for all Non-ANSI text is "rtf" and SHELL to MSWord (which is what I do at the moment).

                      Comment


                      • #12
                        It seems that the only quick & flexible solution for all Non-ANSI text is "rtf" and SHELL to MSWord (which is what I do at the moment).
                        "Quick" and "flexible" are somewhat subjective, but I don't think shelling to Wordpad is the only solution worth considering...

                        1. Use a richedit control yourself. There have to be at least twenty examples of same here.

                        2. You can use Wide Character (Unicode) windows and controls. Demo: Directory List with Non-ASCII (Unicode) characters in file names 5-31-08

                        MCM
                        Michael Mattias
                        Tal Systems (retired)
                        Port Washington WI USA
                        [email protected]
                        http://www.talsystems.com

                        Comment


                        • #13
                          MCM

                          1. Use a richedit control yourself[
                          I use it a lot for Latin/Arabic Editing programs but I have no idea how you would use it for printing

                          (Later: I have just RTFM'd - yes, you can print from the control: now for some heavy reading to try and understand how to do it)

                          2. You can use Wide Character (Unicode) windows and controls
                          I will have a look but I suspect I would have problems with 4-form Arabic which the RichEdit control handles automatically.

                          Bob
                          Last edited by Robert Wallace; 20 Feb 2009, 11:24 AM. Reason: Followed MCM's suggestion

                          Comment


                          • #14
                            Is this the sort of thing you want? Print right to left reflected?
                            Code:
                            'PBCC5 program
                            #COMPILE EXE
                            #DIM NONE
                            
                            FUNCTION PBMAIN () AS LONG
                            
                              XPRINT ATTACH CHOOSE
                              XPRINT GET PPI TO x&,y&
                              
                              GRAPHIC BITMAP NEW 5000, 500 TO hBmp&   'a bitmap big enough to hold whatever text you might print
                              PrintScale!= x&/72   'The approximate difference in scale, the screen is usually 72dpi, should be looked up in final code
                              FONT NEW "Courier New",18 * PrintScale!,1,0,1,0 TO hFont&    '18 point (quarter inch high), bold,
                            
                              MyText$="Text to print backwards red?."
                            
                              GRAPHIC ATTACH hBmp&, 0
                              GRAPHIC SET FONT hFont&
                              GRAPHIC COLOR %BLACK,%WHITE
                              GRAPHIC TEXT SIZE MyText$ TO w&,h&
                            
                              GRAPHIC PRINT MyText$
                            
                              'position on page to print the text
                              WhereToX&=800
                              WhereToY&=400
                            
                              'now copy the bitmap from the graphic to the printer but do it backwads.
                              XPRINT STRETCH hBmp&,0,(0,0)-(w&-1,h&-1) TO (WhereToX&+w&-1,WhereToY&)-(WhereToX&,WhereToY&+h&-1)
                            
                              XPRINT FORMFEED
                              XPRINT CLOSE
                            
                            END FUNCTION

                            Comment


                            • #15
                              Paul

                              Yes it would do - The original RTL problem has now been solved with all your help.

                              However all the "xxxx PRINT" commands seem to be ASCII/ANSI orientated so I cannot use them (as far as I know).

                              I have requested a new feature for an "xxxx PRINT" to work with Unicode as the fonts I normally use have hundreds of Glyphs. (I know there are API commands like "GetCharacterPlacement" but they are way out of my league for a simple non-Latin printing program.)

                              Comment

                              Working...
                              X