Announcement

Collapse
No announcement yet.

FONT END Suggestion - Unless I'm Missing Something

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

  • FONT END Suggestion - Unless I'm Missing Something

    FONT END will fail (illegal function call) if the font is "still in use" per PB documentation. Further investigation reveals that what the reader is meant to infer is that if you do this:

    Code:
    GRAPHIC SET FONT myFont???
    FONT END myFont???
    then FONT END will produce an illegal function call. This makes sense to a casual observer, though it would also make sense that there would be an option to do something like GRAPHIC FONT SET 0, or GRAPHIC FONT UNSET.

    As it is, the ONLY (logical) way to end myFont??? appears to be to attach to another font entirely.

    Not a big deal, but it can come up in certain cases (one may imagine). May I suggest either:

    A. A mechanism of simply detaching the font so that it may be ended without having to resort to unnecessarily attaching to another font.
    or;
    B. That FONT END could, presumably, be made to not fail at all, since it stands to reason that the programmer would be intelligent enough to not END the font that they were still painting with.

    Just a thought.

    P.S. Maybe there is already a command to detach a font (within Powerbasic's command set)... anyone?

  • #2
    Do you have some compilable sample code that shows this generating an error?
    Rod
    In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

    Comment


    • #3
      It will happen in the below code. Don't get me wrong, the error is what is supposed to happen per documentation, so that's not a problem.

      From the PB Help File, under "FONT END":
      If the specified font is still in use by a , a Graphic Control, a Graphic Window, or an XPrint page, an error 5 (Illegal Function Call) will be generated .


      I'm only thinking it would make sense to be able to GRAPHIC UNSET a font. That way a font could be END'ed without needlessly GRAPHIC SET FONT'ing to a different font first.


      Code:
      #COMPILE EXE
      #INCLUDE "win32api.inc"
      
      FUNCTION PBMAIN () AS LONG
      
          GRAPHIC BITMAP NEW 100,100 TO hBMP???
          
          FONT NEW "Arial",20,1 TO hFont???
          GRAPHIC ATTACH hBMP???,0
      
      
          GRAPHIC SET FONT hFont???
          MSGBOX "Look, no error:"+$CRLF+ERROR$(ERR)
      
          FONT END hFont???
          MSGBOX "Look, an ILLEGAL FUNCTION CALL error:"+$CRLF+ERROR$(ERR)
      
      
          GRAPHIC BITMAP END
          
      END FUNCTION
      Last edited by Philip Zeller; 9 Mar 2009, 07:35 PM.

      Comment


      • #4
        If the "GRAPHIC BITMAP END" line precedes the "FONT END" line no error is generated.

        This makes sense to me because there is always a font associated with the GRAPHIC PRINT, GRAPHIC INPUT, and GRAPHIC LINE INPUT statements because of this from under the "GRAPHIC SET FONT" in the help file:
        If no specific font is selected, the default font is MS Sans Serif, 8 point, with no style attributes.
        There must be a font available at all times for those three statements to work(or any other printing), or use of them might create a different error(unknown to me) Additionally, the FONT NEW creates the fonts for other uses besides the GRAPHIC, so FONT END should only be used when you are, in this case, finished with your GRAPHIC ie: after the GRAPHIC BITMAP END statement, not before.

        If you read the FONT NEW help, you'll will see that you can establish several fonts to exist and be ready for use at will, therefore changing to a different font is acceptable and in fact made easier.

        The FONT END statement is there primarily to reclaim the memory space since all the fonts created with FONT NEW statement are destroyed at program end.
        If you create 700 fonts with the FONT NEW statement, and then when none of the fonts are in use you destroy all 700 fonts with FONT END, the default font will be used for any subsequent print jobs, just like if you never created any fonts in the first place.

        PB's method ensures that there is always a font available, and this I think most of us would prefer.

        What is the point of being fontless?
        So why do you want to use the FONT END statement?
        Last edited by Rodney Hicks; 9 Mar 2009, 09:55 PM. Reason: spelling
        Rod
        In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

        Comment


        • #5
          Correct, but being old school myself, I'd like to release that which I'm not using (except the default font, I understand that).

          The point is, there appears to be no way to release every font you've created (if you make 700 fonts, it's simple enough to release 699 of them, but what of the 700th?).

          I guess having worked on systems back in the 70's, programming with 1-4 kilobyte (yes, kilobyte), I just hate the idea of wasting resources.

          Comment


          • #6
            Look at the first line of my last post.
            The code you supplied with that one change creates a font and ends a font, just as it would with 700 of them without an error.

            However, if you were to take the "FONT NEW" statement and place it before the "GRAPHIC BITMAP NEW" statement as well, it might become clear to you that the fonts don't have to be created within the "GRAPHIC" phase of your program.

            That the "FONT NEW" statement doesn't generate the error when used within the "GRAPHIC" phase is significant as well.

            Try this as another way to release the font, trying each of the commented line combos:
            Code:
            #COMPILE EXE
            #INCLUDE "win32api.inc"
            
            FUNCTION PBMAIN () AS LONG
                FONT NEW "Arial",20,1 TO hFont???
                FONT NEW "",0,0 TO Deflt???
                GRAPHIC BITMAP NEW 100,100 TO hBMP???
            
                
                GRAPHIC ATTACH hBMP???,0
            
            
                GRAPHIC SET FONT hFont???
                MSGBOX "Look, no error:"+$CRLF+ERROR$(ERR)
                'GRAPHIC BITMAP END        ' comment out this line to produce the error.
                'GRAPHIC SET FONT Deflt???   'comment out this line to produce the error.
                'GRAPHIC SET FONT 4   'comment out this line to produce the error.
                FONT END hFont???
                IF ERR THEN
                  MSGBOX "Look, an ILLEGAL FUNCTION CALL error:"+$CRLF+ERROR$(ERR)
                ELSE
                  MSGBOX "Look, no error here either:"+$CRLF+ERROR$(ERR)
                END IF
                GRAPHIC BITMAP END   'uncomment to produce error
            
                 MSGBOX "Deflt??? value: "+FORMAT$(Deflt???)
            END FUNCTION
            I do not suggest using this (GRAPHIC SET FONT 4) in any program, it is for educational purposes only.
            Rod
            In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

            Comment


            • #7
              Yes, I understand that. Obviously the fonts have nothing to do with the graphics phase as such.

              Your example is a perfect example of my point. The three solutions each involve either
              • ending that which the font was attached to in order to end the font
              or
              • attaching to a different font
              We should be able to simply DETACH from the font entirely without an ATTACHment to a different font (or better yet, an attachment to the default font which already exists anyway).

              If I create a font I wish to use, use the font, am done with the font, have no need for continued use of non-default font functionality in execution, it would be nice to be able to detach the font and dispose of it.

              Code:
              GRAPHIC BITMAP END        'okay IF you happen to be done w/the bmp.
              GRAPHIC SET FONT Deflt???   'again, 699 of 700...
              GRAPHIC SET FONT 4   'illegal function call
              I am intrigued by GRAPHIC SET FONT 4. I do wish I could do a GRAPHIC SET FONT 0 (or 4... whatever) and simply detach from my unneeded font that way, though it still gives an illegal function call on FONT END (it's still attached).

              Is there a method of determining the font handle for the DEFAULT font? That would also solve the problem (since it's going to exist anyway, it'd seem logical to attach to it). Something like:

              Code:
              GRAPHIC SET FONT whateverthedefaultfontiswhichwouldbegreattoknowthehandlefor
              FONT END thefontinolongerneed

              Comment


              • #8
                Code:
                #COMPILE EXE
                #INCLUDE "win32api.inc"
                
                FUNCTION PBMAIN () AS LONG
                    FONT NEW "Arial",20,1 TO hFont???
                    FONT NEW "",0,0 TO Deflt???
                    GRAPHIC BITMAP NEW 100,100 TO hBMP???
                
                
                    GRAPHIC ATTACH hBMP???,0
                
                
                    GRAPHIC SET FONT hFont???
                    MSGBOX "Look, no error:"+$CRLF+ERROR$(ERR)
                   
                    
                    GRAPHIC SET FONT 4  
                    FONT END hFont???
                    IF ERR THEN
                      MSGBOX "Look, an ILLEGAL FUNCTION CALL error:"+$CRLF+ERROR$(ERR)
                    ELSE
                      MSGBOX "Look, no error here either:"+$CRLF+ERROR$(ERR)
                    END IF
                     GRAPHIC BITMAP END
                
                     MSGBOX "Deflt??? value: "+FORMAT$(Deflt???)
                END FUNCTION
                This arrangement of commented out lines compiles and runs on my machine and does not produce an error and you could get rid of all 700 fonts.
                The second FONT NEW statement will create the numeric value for the default font and store it in Deflt???, and it (the value) is displayed in the third MSGBOX.
                From the help file on FONT NEW:
                If the font creation fails, the value zero (0) is assigned to fhndl.
                This is why there cannot be a GRAPHIC SET FONT 0 as 0 is an error condition.
                Rod
                In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                Comment


                • #9
                  But...

                  When you do:
                  Code:
                  FONT NEW "",0,0 TO Deflt???
                  You appear be actually creating another font (albeit a copy of what is the default font). Check the value of Deflt???, it's four. The value of hFont??? is three.

                  Wait a minute, thinks I... it's a no brainer now... This lead me quickly to the solution, in the form:

                  Code:
                  #COMPILE EXE
                  #INCLUDE "win32api.inc"
                  
                  FUNCTION PBMAIN () AS LONG
                  
                      'make a font
                      FONT NEW "Arial",20,1 TO hFont???
                  
                      'attach it to anything, thus making it be locked
                      GRAPHIC BITMAP NEW 100,100 TO hBMP???
                      GRAPHIC ATTACH hBMP???,0
                      GRAPHIC SET FONT hFont???
                  
                      'this was the key.  There are (apparently)
                      'TWO fonts we CAN attach to which already
                      'exist.  So, I'll attach to 1 or 2.
                      GRAPHIC SET FONT 1
                  
                      'now I can end the ONLY font I created.
                      FONT END hFont???
                  
                      MSGBOX "All requirements satisfied... no need to make ANY additional fonts, and no error, too!  We just attached to a default font with no addl. overhead... Life is sweet:"+$CRLF+ERROR$(ERR)
                  
                  END FUNCTION
                  So, in conclusion, the key was GRAPHIC SET FONT 1.

                  Might be a good thing to put into the documentation.
                  Last edited by Philip Zeller; 10 Mar 2009, 11:39 PM.

                  Comment


                  • #10
                    I'm curious, why would you set it to 1 when the default(at present) is 4?
                    Personally, I'd use the
                    Code:
                    FONT NEW "",0,0 TO Deflt???
                    GRAPHIC SET FONT Deflt???
                    because, should there be changes GRAPHIC SET FONT or FONT NEW in future versions of the compiler GRAPHIC SET FONT Deflt??? makes more sense than GRAPHIC SET FONT 4 (or whatever number you use) and will(may) require less code updating.
                    Interestingly enough I changed the Arial in your code to Lucida Console and still got 3. This might be due to the format$() function in the MSGBOX not rendering the full value as we're using it, did not investigate that.(That doesn't really make sense either, but at the moment I'm tired and grasping at straws.)
                    Last edited by Rodney Hicks; 11 Mar 2009, 12:33 AM. Reason: clarification
                    Rod
                    In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                    Comment


                    • #11
                      I'm curious, why would you set it to 1 when the default(at present) is 4?

                      You've concluded that the default font is four... It's not that the "default" is four. Not really. You see, the first FONT NEW we call will create a font handled 3, the second FONT NEW will create a font handled 4, then 5, etc. (the handles are predictable and ascending). The font handles have nothing to do with the specific parameters (font face, etc.).

                      This is how I determined the first 2 fonts to pre-exist. Try GRAPHIC SET FONT 1 and GRAPHIC SET FONT 2 and observe the resultant text .

                      You see, when you create the font Deflt??? in your code, and you don't specify a font face or other characteristics, this does not mean that you're going to get the handle to the actual default font returned. You are merely creating a NEW font (3 or above), using the default characteristics ... it's still a new font and new handle.

                      Thus, we would still be left with the new font undisposed.

                      It should be quite safe to call GRAPHIC SET FONT 1 (or CONTROL SET FONT 1, XPRINT SET FONT 1, etc.), because FONT 1 must exist.

                      Now, of course, if, in a future version of PowerBasic, the default fonts aren't assigned font handles ascending from 1, this would be a problem, but that would be an odd thing indeed.

                      Since we know that the fonts do, in fact, start at 1 (as you said, font 0 can't (really) exist), we can always select it (1) (thus deselecting any font we have made).

                      Basically, I've found that fonts 1 and 2 are built in. No matter how many fonts I create in testing, their handles simply ascend up from there.
                      Last edited by Philip Zeller; 11 Mar 2009, 03:16 AM.

                      Comment


                      • #12
                        What you're saying makes sense, but then I've had some sleep, and explains all else that I was wondering about, which I wouldn't have been wondering about if you hadn't wanted to destroy the font while it was still being used kind of thingy.
                        So what you're thinking is if you create 700 fonts you'll have 2 intrinsic as well for 702 fonts.

                        All is good.
                        Have you tried actually using 1 or 2 to print anything anywhere?
                        Rod
                        In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                        Comment


                        • #13
                          They look like this:

                          Code:
                          #COMPILE EXE
                          
                          FUNCTION PBMAIN () AS LONG
                          
                              GRAPHIC WINDOW "Fonts", 100,100,400, 65 TO hWin???
                              GRAPHIC ATTACH hWin???,0
                          
                              GRAPHIC SET FONT 1
                              GRAPHIC PRINT "This is font 1 (built in)"
                              
                              GRAPHIC SET FONT 2
                              GRAPHIC PRINT "This is font 2 (built in)"
                              
                              FONT NEW "Arial",25 TO hFont???
                              GRAPHIC SET FONT hFont???
                              GRAPHIC PRINT "This is our font, number "+FORMAT$(hFont???)
                              
                              SLEEP 5000
                              
                          
                          END FUNCTION
                          Interesting, if somewhat trivial to know this.

                          Comment


                          • #14
                            Yes it is.
                            Rod
                            In some future era, dark matter and dark energy will only be found in Astronomy's Dark Ages.

                            Comment

                            Working...
                            X