Announcement

Collapse
No announcement yet.

Graphic Print Borders

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

  • Graphic Print Borders

    When using Graphic Print, there seems to be a really large print area above and below the letter - where the background color covers a lot of surface not related to the letter itself. I'm not aware of any way to reduce that in PowerBASIC.

    I can use a transparent background in the print operation of course, but sometimes I want the background behind the letter to be a specific color and transparency is not desired.

    To print letters vertically close to one another I have to add extra code to hide the undesirable bordering color. For example, I might create a Graphic Memory Bitmap containing the letter and then use Graphic Copy to copy only the part that I want to the final location for display to the user.


    Click image for larger version  Name:	pb_2258.jpg Views:	1 Size:	7.6 KB ID:	807310


  • #2
    Wrong code?

    Is that an upper of lower case "X" ?

    A lot depends on the font you are using - they all have different amounts of space for descenders and ascenders and "line gap"/"leading". Have you tried diffrent upper and lower case characters and different fonts?

    Click image for larger version

Name:	TypeTermsColor.jpg?ssl=1.jpg
Views:	125
Size:	68.7 KB
ID:	807317

    Comment


    • #3
      All of those margins/spacing etc are defined by the font itself.

      I personally find vertical text hard to read unless the characters are rotated 90 degrees, especially lower case.
      "Not my circus, not my monkeys."

      Comment


      • #4
        When using Graphic Print...,
        PATIENT: " Doctor, It hurts when I do this."

        DOCTOR: "Then don't do that. "

        That is, have you looked at alternatives to GRAPHIC PRINT for this application?


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

        Comment


        • #5
          Howdy, Stuart!
          Yep. Copied the wrong code. Deleted what was there. Thanks for pointing that out.

          Howdy, Eric!
          I was thinking of two lines of content, independently printed close to one another, one above the other. The last printed line of content will overlap the previous line because of the large background area that is painted with the background color. But to your point, I guess I'd have to manipulate the font itself to get the results I want.

          Howdy, MCM!
          The app where this came to my attention already uses a Graphic control, so use of the Graphic Print is convenient. But as I noted, I can use other Graphic commands to get around it. I just wondered if there was a way to minimize the amount of margin the font requires. Eric's comment points the way to that although it is not a Graphic solution.

          Comment


          • #6
            Howdy, Stuart!

            Yes, different fonts give differing results. All capital X's. None seem to have a "tight" border.

            Click image for larger version  Name:	pb_2259.jpg Views:	0 Size:	10.2 KB ID:	807321

            Code:
            'Compilable Example:
            #Compile Exe
            #Dim All
            #Include "Win32API.inc"
            
            Global hDlg As Dword
            
            Function PBMain() As Long
               Dialog New Pixels, 0, "PowerBASIC",300,300,400,200, %WS_OverlappedWindow To hDlg
               Control Add Graphic, hDlg, 500,"",0,0,400,200
               Graphic Color %Yellow, %Blue
               Graphic Set Pos(10,50)
               Graphic Font "Tahoma", 72, 1
               Graphic Print "X"
               Graphic Set Pos(90,50)
               Graphic Font "Arial Black", 72, 1
               Graphic Print "X"
               Graphic Set Pos(175,50)
               Graphic Font "Courier New", 72, 1
               Graphic Print "X"
               Dialog Show Modal hDlg
            End Function

            Comment


            • #7
              Use transparency over a box of the background you want as :
              Code:
              #COMPILE EXE
              #DIM ALL
              #INCLUDE "Win32API.inc"
              
              GLOBAL hDlg AS DWORD
              
              FUNCTION PBMAIN() AS LONG
                LOCAL tw, th, gw, gh, cw, ch AS LONG
                 DIALOG NEW PIXELS, 0, "PowerBASIC",300,300,400,200, %WS_OVERLAPPEDWINDOW TO hDlg
                 CONTROL ADD GRAPHIC, hDlg, 500,"",0,0,400,200
                ' graphic clear %blue
                ' Graphic Color %Yellow, %BLUE
                 GRAPHIC COLOR %YELLOW, -2
                 GRAPHIC BOX (10,65)-(76,155),0,%BLUE,%BLUE
                 GRAPHIC SET POS(10,50)
                 GRAPHIC FONT "Tahoma", 72, 1
                 GRAPHIC TEXT SIZE "X" TO tw, th
                 GRAPHIC CHR SIZE TO gw, gh
                 GRAPHIC CELL SIZE TO cw, ch
                 GRAPHIC PRINT "X"
                 GRAPHIC COLOR %YELLOW, %BLUE
                 GRAPHIC SET POS (110,50)
                 GRAPHIC PRINT "X"
              '   Graphic Set Pos(90,50)
              '   Graphic Font "Arial Black", 72, 1
              '   Graphic Print "X"
              '   Graphic Set Pos(175,50)
              '   Graphic Font "Courier New", 72, 1
              '   Graphic Print "X"
              '   graphic set pos (10,185)
              '   GRAPHIC FONT "Courier New", 12, 1
              '   GRAPHIC PRINT tw; th, gw; gh, cw; ch
                 DIALOG SHOW MODAL hDlg
              END FUNCTION
              Rod
              I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

              Comment


              • #8
                Write once, use many times. (I'm sure there is an SDK solution but in the time it takes to look it up, I wrote this which is tweakable.)
                Code:
                'Compilable Example:
                #COMPILE EXE
                #DIM ALL
                #INCLUDE "Win32API.inc"
                GLOBAL hDlg AS DWORD
                SUB get_alpha_extent(char AS STRING, fnt AS LONG,  top AS LONG, btm AS LONG, lft AS LONG, _
                        rht AS LONG, vmrgn AS LONG, hmrgn AS LONG, cw AS LONG, ch AS LONG, px AS LONG, py AS LONG)
                  LOCAL ndx, indx, cx, cy, klr, hbmp AS LONG
                  GRAPHIC BITMAP NEW cw, ch TO hbmp
                  GRAPHIC ATTACH hbmp,0
                  GRAPHIC SET FONT fnt
                  GRAPHIC CLEAR %WHITE
                  GRAPHIC COLOR %BLACK,-2
                  GRAPHIC SET POS (0,0)
                  GRAPHIC PRINT char
                  cx=cw\2
                  cy=ch\2
                  lft=cw\2
                  rht=cw\2
                  top=ch\2
                  btm=ch\2
                  FOR ndx=0 TO cw
                    FOR indx=0 TO ch
                      GRAPHIC GET PIXEL (ndx,indx) TO klr
                      IF klr= %BLACK THEN
                        IF ndx<cx AND ndx<lft THEN lft=ndx
                        IF ndx>cx AND ndx>rht THEN rht=ndx
                        IF indx<cy AND indx<top THEN top=indx
                        IF indx>cy AND indx>btm THEN btm=indx
                      END IF
                    NEXT indx
                  NEXT ndx
                  lft=lft-hmrgn
                  lft=px+lft
                  rht=px+lft+rht-hmrgn
                  top=top-vmrgn
                  top=py+top
                  btm=py+btm+vmrgn +vmrgn
                  IF ISTRUE hbmp THEN
                    GRAPHIC ATTACH hbmp,0
                    GRAPHIC BITMAP END
                  END IF
                  GRAPHIC ATTACH hdlg, 500
                END SUB
                
                FUNCTION PBMAIN() AS LONG
                  LOCAL tw, th, gw, gh, cw, ch, px, py AS LONG
                  LOCAL fnt, top, btm, lft, rht, vmrgn, hmrgn AS LONG
                  LOCAL char AS STRING
                   DIALOG NEW PIXELS, 0, "PowerBASIC",300,300,500,200, %WS_OVERLAPPEDWINDOW TO hDlg
                   CONTROL ADD GRAPHIC, hDlg, 500,"",0,0,500,200
                   FONT NEW "Tahoma", 72, 0 TO fnt
                   GRAPHIC SET FONT fnt
                   vmrgn=2
                   hmrgn=2
                   px=10
                   py=50
                   char ="XYW" ' one char or many, all on one line
                   GRAPHIC TEXT SIZE char TO tw, th
                   GRAPHIC SET POS(px, py)
                   get_alpha_extent char,fnt, top, btm, lft, rht, vmrgn, hmrgn, tw, th, px, py
                   GRAPHIC COLOR %YELLOW, -2
                   GRAPHIC BOX (lft,top)-(rht,btm),0,%BLUE,%BLUE
                   GRAPHIC PRINT char
                   GRAPHIC COLOR %YELLOW, %BLUE
                   GRAPHIC SET POS (250,50)
                   GRAPHIC PRINT char
                   DIALOG SHOW MODAL hDlg
                END FUNCTION
                Click image for larger version

Name:	char_extent.gif
Views:	98
Size:	7.2 KB
ID:	807337
                Rod
                I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                Comment


                • #9
                  Originally posted by Rodney Hicks View Post
                  Write once, use many times. (I'm sure there is an SDK solution but in the time it takes to look it up, I wrote this which is tweakable.)
                  Tweaked! No longer requires a call to get_alpha_extent for every GRAPHIC PRINT.. Only needs to be called when you want to set/change font, character string or margins

                  '
                  Code:
                  'Compilable Example:
                  #COMPILE EXE
                  #DIM ALL
                  GLOBAL hDlg AS DWORD
                  SUB get_alpha_extent(char AS STRING, fnt AS DWORD,vmrgn  AS LONG, hmrgn AS LONG, _
                                       boxX AS LONG,boxY AS LONG,charX AS LONG,charY AS LONG)
                    LOCAL ndx, indx, cx, cy, klr, hbmp,tw,th,lft,rht,top,btm AS LONG
                    GRAPHIC TEXT SIZE char TO tw, th
                    GRAPHIC BITMAP NEW tw, th TO hbmp
                    GRAPHIC ATTACH hbmp,0
                    GRAPHIC SET FONT fnt
                    GRAPHIC CLEAR %WHITE
                    GRAPHIC COLOR %BLACK,-2
                    GRAPHIC SET POS (0,0)
                    GRAPHIC PRINT char
                    cx=tw\2
                    cy=th\2
                    lft=tw\2
                    rht=tw\2
                    top=th\2
                    btm=th\2
                    FOR ndx=0 TO tw
                      FOR indx=0 TO th
                        GRAPHIC GET PIXEL (ndx,indx) TO klr
                        IF klr= %BLACK THEN
                          IF ndx<cx AND ndx<lft THEN lft=ndx
                          IF ndx>cx AND ndx>rht THEN rht=ndx
                          IF indx<cy AND indx<top THEN top=indx
                          IF indx>cy AND indx>btm THEN btm=indx
                        END IF
                      NEXT indx
                    NEXT ndx
                    boxX = rht + hmrgn*2
                    boxY = btm - top + vmrgn*2
                    charX = hmrgn
                    charY = vmrgn - top
                    IF ISTRUE hbmp THEN
                      GRAPHIC ATTACH hbmp,0
                      GRAPHIC BITMAP END
                    END IF
                    GRAPHIC ATTACH hdlg, 500
                  END SUB
                  
                  FUNCTION PBMAIN() AS LONG
                    LOCAL px,py,vmrgn, hmrgn,BoxX,BoxY,charX,charY AS LONG
                    LOCAL fnt AS DWORD
                    LOCAL char AS STRING
                     DIALOG NEW PIXELS, 0, "PowerBASIC",300,300,500,200, %WS_OVERLAPPEDWINDOW TO hDlg
                     CONTROL ADD GRAPHIC, hDlg, 500,"",0,0,500,200
                     FONT NEW "Tahoma", 74, 0 TO fnt
                     GRAPHIC SET FONT fnt
                     vmrgn=2
                     hmrgn=2
                     char ="Xghj"
                     get_alpha_extent char,fnt,vmrgn, hmrgn,boxX,BoxY,charX,charY
                     GRAPHIC COLOR %YELLOW, -2
                     px = 0
                     py = 0
                     GRAPHIC BOX (px,py)-(Px+BoxX,Py+BoxY),0,%BLUE,%BLUE
                     GRAPHIC SET POS(px+charX,py+chary)
                     GRAPHIC PRINT char
                     px = 100
                     py = 100
                     GRAPHIC BOX (px,pY)-(PX+BoxX,Py+BoxY),0,%BLUE,%BLUE
                     GRAPHIC SET POS(px+charX, py+chary)
                     GRAPHIC PRINT char
                  
                     DIALOG SHOW MODAL hDlg
                  END FUNCTION
                  '

                  Comment


                  • #10
                    Very nice, Stuart! That's exactly the feature that needed tweaking most!
                    Rod
                    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                    Comment


                    • #11
                      Streamilined a bit and used a UDT

                      '
                      Code:
                      'Compilable Example:
                      #COMPILE EXE
                      #DIM ALL
                      GLOBAL hDlg AS DWORD
                      
                      TYPE BoxedChars
                      fnt AS DWORD  ' font handle
                      chars AS STRINGZ * 255
                      boxX AS LONG  'end x for box
                      boxY AS LONG  'end y for box
                      charX AS LONG  'X offset for character(s)
                      charY AS LONG  'y offset for character(s)
                      hMrgn AS LONG 'Horizontal margin
                      vmrgn AS LONG ' Vertical Margin
                      fgnd AS LONG ' Foreground Colour
                      bgnd AS LONG ' Background Colour
                      px AS LONG 'x position of boxed characters
                      py AS LONG 'y position of boxed characters
                      END TYPE
                      
                      FUNCTION PBMAIN() AS LONG
                        LOCAL bc AS BoxedChars
                        LOCAL fnt AS DWORD
                      
                         DIALOG NEW PIXELS, 0, "PowerBASIC",300,300,500,200, %WS_OVERLAPPEDWINDOW TO hDlg
                         CONTROL ADD GRAPHIC, hDlg, 500,"",0,0,500,200
                         FONT NEW "Tahoma", 74, 0 TO fnt
                         GRAPHIC SET FONT fnt
                      
                         bc.fnt = fnt
                         bc.vmrgn=2
                         bc.hmrgn=2
                         bc.chars ="X"
                         get_alpha_extent bc
                      
                         bc.px = 0
                         bc.py = 0
                         bc.fgnd = %YELLOW
                         bc.bgnd = %BLUE
                         PrintBoxedChars bc
                      
                         bc.px = 100
                         bc.py = 100
                         bc.fgnd = %RED
                         PrintBoxedChars bc
                      
                         bc.px = 300
                         bc.py = 100
                         bc.bgnd = %YELLOW
                         PrintBoxedChars bc
                      
                         DIALOG SHOW MODAL hDlg
                      END FUNCTION
                      
                      SUB get_alpha_extent(bc AS BoxedChars)
                        LOCAL ndx, indx,klr, hbmp,tw,th,lft,rht,top,btm AS LONG
                        GRAPHIC TEXT SIZE bc.chars TO tw, th
                        GRAPHIC BITMAP NEW tw, th TO hbmp
                        GRAPHIC ATTACH hbmp,0
                        GRAPHIC SET FONT bc.fnt
                        GRAPHIC CLEAR %WHITE
                        GRAPHIC COLOR %BLACK,-2
                        GRAPHIC PRINT bc.chars
                        lft=tw\2
                        rht=lft
                        top=th\2
                        btm=top
                        FOR ndx=0 TO tw
                          FOR indx=0 TO th
                            GRAPHIC GET PIXEL (ndx,indx) TO klr
                            IF klr= %BLACK THEN
                              IF ndx<lft THEN lft=ndx
                              IF ndx>rht THEN rht=ndx
                              IF indx<top THEN top=indx
                              IF indx>btm THEN btm=indx
                            END IF
                          NEXT indx
                        NEXT ndx
                        bc.boxX = rht + bc.hmrgn*2
                        bc.boxY = btm - top + bc.vmrgn*2
                        bc.charX = bc.hmrgn
                        bc.charY = bc.vmrgn - top
                        IF ISTRUE hbmp THEN
                          GRAPHIC ATTACH hbmp,0
                          GRAPHIC BITMAP END
                        END IF
                        GRAPHIC ATTACH hdlg, 500
                      END SUB
                      
                      SUB PrintBoxedChars(bc AS BoxedChars)
                         GRAPHIC COLOR bc.fgnd, -2
                         GRAPHIC BOX (bc.px,bc.pY)-(bc.PX+bc.BoxX,bc.Py+bc.BoxY),0,bc.bgnd,bc.bgnd
                         GRAPHIC SET POS(bc.px+bc.charX, bc.py+bc.chary)
                         GRAPHIC PRINT bc.chars
                      END SUB
                      '

                      Comment


                      • #12
                        Finally tested your latest, Stuart. Looks real good, even better with vmrgn and hmrgn set to 5 instead of 2.

                        Of course, the original poster hasn't chimed in, but you've made me happy with it. Thanks..
                        Rod
                        I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                        Comment


                        • #13
                          Too late to edit post #11. There was a bug in the CharX and BoxX calcuations. (very noticeable if you use an "i" instead of an "X" with zero margins
                          Corrected version and I've also included showing other text in a different font between the BoxedChar calls.
                          '
                          Code:
                          'Compilable Example:
                          #COMPILE EXE
                          #DIM ALL
                          GLOBAL hDlg AS DWORD
                          
                          TYPE BoxedChars
                              fnt AS DWORD  ' font handle
                              chars AS STRINGZ * 255
                              hMrgn AS LONG 'Horizontal margin
                              vmrgn AS LONG ' Vertical Margin
                              fgnd AS LONG ' Foreground Colour
                              boxX AS LONG  'end x for box
                              boxY AS LONG  'end y for box
                              charX AS LONG  'X offset for character(s)
                              charY AS LONG  'y offset for character(s)
                              bgnd AS LONG ' Background Colour
                              px AS LONG 'x position of boxed characters
                              py AS LONG 'y position of boxed characters
                          END TYPE
                          
                          FUNCTION PBMAIN() AS LONG
                            LOCAL bc AS BoxedChars
                            LOCAL fntB,fntN AS DWORD
                          
                             DIALOG NEW PIXELS, 0, "PowerBASIC",300,300,500,200, %WS_OVERLAPPEDWINDOW TO hDlg
                             CONTROL ADD GRAPHIC, hDlg, 500,"",0,0,500,200
                             FONT NEW "Tahoma", 20, 0 TO fntn
                             FONT NEW "Tahoma", 78, 0 TO fntB
                          
                             GRAPHIC SET FONT fntN
                             GRAPHIC SET POS(100,10)
                             GRAPHIC COLOR %GREEN, %WHITE
                             GRAPHIC PRINT "Normal font"
                          
                             bc.fnt = fntB
                             bc.vmrgn=0
                             bc.hmrgn=0
                             bc.chars ="X"
                             get_alpha_extent bc
                          
                             bc.px = 0
                             bc.py = 0
                             bc.fgnd = %YELLOW
                             bc.bgnd = %BLUE
                             PrintBoxedChars bc
                          
                             bc.px = 100
                             bc.py = 100
                             bc.fgnd = %RED
                             PrintBoxedChars bc
                          
                             GRAPHIC SET FONT fntN
                             GRAPHIC SET POS(250,10)
                             GRAPHIC COLOR %GREEN, %BLACK
                             GRAPHIC PRINT "Normal font again"
                          
                             bc.px = 300
                             bc.py = 100
                             bc.bgnd = %YELLOW
                             PrintBoxedChars bc
                          
                             DIALOG SHOW MODAL hDlg
                          END FUNCTION
                          
                          SUB get_alpha_extent(bc AS BoxedChars)
                            LOCAL ndx, indx,klr, hbmp,tw,th,lft,rht,top,btm AS LONG
                            GRAPHIC SET FONT bc.fnt
                            GRAPHIC TEXT SIZE bc.chars TO tw, th
                            GRAPHIC BITMAP NEW tw, th TO hbmp
                            GRAPHIC ATTACH hbmp,0
                            GRAPHIC SET FONT bc.fnt
                            GRAPHIC CLEAR %WHITE
                            GRAPHIC COLOR %BLACK,-2
                            GRAPHIC PRINT bc.chars
                            lft=tw
                            rht=0
                            top=th
                            btm=0
                            FOR ndx=0 TO tw
                              FOR indx=0 TO th
                                GRAPHIC GET PIXEL (ndx,indx) TO klr
                                IF klr= %BLACK THEN
                                  IF ndx<lft THEN lft=ndx
                                  IF ndx>rht THEN rht=ndx
                                  IF indx<top THEN top=indx
                                  IF indx>btm THEN btm=indx
                                END IF
                              NEXT indx
                            NEXT ndx
                            bc.boxX = rht + bc.hmrgn*3 -lft +1
                            bc.boxY = btm - top + bc.vmrgn*3 + 1
                            bc.charX = bc.hmrgn -lft
                            bc.charY = bc.vmrgn - top
                            IF ISTRUE hbmp THEN
                              GRAPHIC ATTACH hbmp,0
                              GRAPHIC BITMAP END
                            END IF
                            GRAPHIC ATTACH hdlg, 500
                          END SUB
                          
                          SUB PrintBoxedChars(bc AS BoxedChars)
                             GRAPHIC SET FONT bc.fnt
                             GRAPHIC COLOR bc.fgnd, -2
                             GRAPHIC BOX (bc.px,bc.pY)-(bc.PX+bc.BoxX,bc.Py+bc.BoxY),0,bc.bgnd ,bc.bgnd
                             GRAPHIC SET POS(bc.px+bc.charX, bc.py+bc.chary)
                             GRAPHIC PRINT bc.chars
                          END SUB
                          '

                          Comment


                          • #14
                            I hadn't tried other characters. Xyl looks odd whereas Xylophone looks not too bad. Didn't try smaller fonts.
                            This has turned out pretty good, but I'm not going to suggest the next tweak as I have other irons in the fire.
                            Rod
                            I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                            Comment


                            • #15
                              Howdy, Guys!

                              >>>Of course, the original poster hasn't chimed in,

                              Thanks for the posts and I'll look at the examples today - life keeps getting in the way of having coding fun!

                              Comment


                              • #16
                                Howdy, Stuart and Rodney!

                                I like your codes as a way to get an exact answer. Still playing with it.

                                Here's something way more minimal - less code but not as perfect a result.

                                My starting point is that I have a fixed square area, such as 128x128, in which to print the letter without flowing outside the area.

                                I choose the font size that will create the largest letter that will fit in the box, typically fontsize = size of box, but depends somewhat on the individual font.

                                Click image for larger version  Name:	pb_2260.jpg Views:	0 Size:	6.5 KB ID:	807395

                                Code:
                                'Compilable Example:
                                #Compile Exe
                                #Dim All
                                #Include "Win32API.inc"
                                
                                Global hDlg, hBMP As Dword
                                
                                Function PBMain() As Long
                                   Local x,y,xOffset,yOffSet As Long
                                   Dialog New Pixels, 0, "PowerBASIC",300,300,150,150, %WS_OverlappedWindow To hDlg
                                   Control Add Graphic, hDlg, 500,"",0,0,150,150
                                   Graphic Clear
                                   Graphic Bitmap New 128, 128 To hBMP
                                   Graphic Attach hBMP, 0
                                   Graphic Color %Yellow, %Blue
                                   Graphic Clear
                                   Graphic Font "Courier New", 128, 1
                                   x = (128-Graphic(Text.Size.X,"X"))/2 + xOffset
                                   y = (128-Graphic(Text.Size.Y,"X"))/2 + yOffset
                                   Graphic Set Pos(x,y)
                                   Graphic Print "X"
                                   Graphic Attach hDlg, 500
                                   Graphic Copy hBMP, 0 To (11,11)
                                   Dialog Show Modal hDlg
                                End Function
                                If I have a specific font to work with, I can tweak the xOffset and yOffset (zero in this example) to be better positioning. I can get those using one of the code segment from your examples above.

                                Comment


                                • #17
                                  Howdy Gary,

                                  Yep, works fine for an uppercase X. Not necessarily so for other characters and fonts

                                  Descenders:
                                  Click image for larger version

Name:	lowerg.jpg
Views:	47
Size:	6.4 KB
ID:	807401Click image for larger version

Name:	upperQ.jpg
Views:	40
Size:	5.6 KB
ID:	807402

                                  Courier V Tahoma (both lower case "i":

                                  Click image for larger version

Name:	loweri.jpg
Views:	39
Size:	4.9 KB
ID:	807403 Click image for larger version

Name:	tahomai.jpg
Views:	39
Size:	4.8 KB
ID:	807404

                                  Comment


                                  • #18
                                    Shades of Joni Mitchell, "Something's lost and something's gained in coding every day!"
                                    Gary, your minimal code example could be shortened with:
                                    x=10 + xOffset
                                    y=-(25 + yOffset)
                                    or something like that instead of
                                    x = (128-GRAPHIC(TEXT.SIZE.X,"X"))/2 + xOffset
                                    y = (128-GRAPHIC(TEXT.SIZE.Y,"X"))/2 + yOffset
                                    As Stuart points out, getting additional letters to line up, which you mentioned in the first post, will be extra work.

                                    "Both sides now": write once, use many times vs minimal code, adjusted every time. Up side and down side to each
                                    YMMV, as some others are wont to say.
                                    Rod
                                    I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                                    Comment


                                    • #19
                                      Howdy, Stuart!

                                      Yes, the font size has to be adjusted so that all of the letters in the font will fit within the print area. I could see how to loop through all the possible letters using this ...

                                      Code:
                                       Function GetFontSize_Graphic2(w As Long, h As Long, txt$, scalefactor As Single, fontName$) As Long
                                          Local x As Long, y As Long
                                          Graphic Font fontName$, 1000, 1
                                          Graphic Text Size txt$ To x,y
                                          Function=  1000/IIF( x/w > y/h , x/(w*scalefactor) , y/(h*scalefactor) )
                                      End Function
                                      ... but that defeats the minimal theme and doesn't solve the problem that each font may place the letter at different vertical positions in the output.

                                      The accurate answer keeps pointing back to your code above.

                                      But I would think there's an API that will point out the x,y position of the upper left point of the actual letter in the printed output - the x/y offset that I mention above, without resorting to a loop as Rodney and your codes use. I'll nose around some more.

                                      Comment


                                      • #20
                                        There is GetTextExtentPoint, as a starting point, and by the time you're finished with it, I don't see much gain over Stuart's last submission, particularly timewise. That code gives you single characters, multiple character-single lines, margin capabilities with most fonts. Write once, use many times isn't all bad.

                                        FWIW, before I first posted the code, I tried to size all alpha characters for a font at once but the resulting size wasn't much different than normal text size.
                                        Rod
                                        I want not 'not', not Knot, not Knott, not Nott, not knot, not naught, not nought, but aught.

                                        Comment

                                        Working...
                                        X