FONT: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 14: Line 14:
{{PageDescription}}
{{PageDescription}}
* Predefined '''QB64''' font handle numbers can be used before freeing a font:
* Predefined '''QB64''' font handle numbers can be used before freeing a font:
**'''_FONT 8 ''' - default font for [[SCREEN (statement)|SCREEN]] 1, 2, 7, 8 or 13
**'''_FONT 8 ''' - default font for [[SCREEN]] 1, 2, 7, 8 or 13
**'''_FONT 14''' - default font for [[SCREEN (statement)|SCREEN]] 9 or 10
**'''_FONT 14''' - default font for [[SCREEN]] 9 or 10
**'''_FONT 16''' - default font for [[SCREEN (statement)|SCREEN]] 0 ([[WIDTH]] 80, 25 text only), 11 or 12
**'''_FONT 16''' - default font for [[SCREEN]] 0 ([[WIDTH]] 80, 25 text only), 11 or 12
**'''_FONT 9, 15''' and '''17''' are the double width versions of 8, 14 and 16 respectively in text '''SCREEN 0 only'''.
**'''_FONT 9, 15''' and '''17''' are the double width versions of 8, 14 and 16 respectively in text '''SCREEN 0 only'''.
* [[Unicode]] characters can be assigned to a monospace font that contains those unicode characters using the [[_MAPUNICODE]] TO [[ASCII]] mapping statement. The optional '''IME cyberbit.ttf''' font included with QB64 can also be used.
* [[Unicode]] characters can be assigned to a monospace font that contains those unicode characters using the [[_MAPUNICODE]] TO [[ASCII]] mapping statement. The optional '''IME cyberbit.ttf''' font included with QB64 can also be used.
Line 28: Line 28:
''Example:'' Previewing a font in SCREEN 0. A different true type font can be substituted below.
''Example:'' Previewing a font in SCREEN 0. A different true type font can be substituted below.
{{CodeStart}}
{{CodeStart}}
fontpath$ = {{Cl|ENVIRON$}}({{Text|<nowiki>"SYSTEMROOT"</nowiki>|#FFB100}}) + {{Text|<nowiki>"\fonts\lucon.ttf"</nowiki>|#FFB100}} {{Text|<nowiki>'Find Windows Folder Path.</nowiki>|#919191}}
{{Cl|DO}}: {{Cl|CLS}}
    {{Cl|DO}}
        style$ = {{Text|<nowiki>"MONOSPACE"</nowiki>|#FFB100}}
        {{Cl|PRINT}}
        {{Cl|INPUT}} {{Text|<nowiki>"Enter A FONT Size 8 TO 25: "</nowiki>|#FFB100}}, fontsize%
    {{Cl|DO...LOOP|LOOP UNTIL}} fontsize% > {{Text|7|#F580B1}} {{Cl|AND (boolean)|AND}} fontsize% < {{Text|26|#F580B1}}
    {{Cl|DO}}
        {{Cl|PRINT}}
        {{Cl|INPUT}} {{Text|<nowiki>"Enter (0) for REGULAR OR (1) for ITALIC FONT: "</nowiki>|#FFB100}}, italic%
    {{Cl|DO...LOOP|LOOP UNTIL}} italic% = {{Text|0|#F580B1}} {{Cl|OR (boolean)|OR}} italic% = {{Text|1|#F580B1}}
    {{Cl|DO}}
        {{Cl|PRINT}}
        {{Cl|INPUT}} {{Text|<nowiki>"Enter (0) for REGULAR OR (1) for BOLD FONT: "</nowiki>|#FFB100}}, bold%
    {{Cl|DO...LOOP|LOOP UNTIL}} italic% = {{Text|0|#F580B1}} {{Cl|OR (boolean)|OR}} italic% = {{Text|1|#F580B1}}
    {{Cl|IF}} italic% = {{Text|1|#F580B1}} {{Cl|THEN}} style$ = style$ + {{Text|<nowiki>", ITALIC"</nowiki>|#FFB100}}
    {{Cl|IF}} bold% = {{Text|1|#F580B1}} {{Cl|THEN}} style$ = style$ + {{Text|<nowiki>", BOLD"</nowiki>|#FFB100}}


fontpath$ = {{Cl|ENVIRON$}}("SYSTEMROOT") + "\fonts\lucon.ttf" 'Find Windows Folder Path.
    {{Cl|GOSUB}} ClearFont
{{Cl|DO}}: {{Cl|CLS}}
     font& = {{Cl|_LOADFONT}}(fontpath$, fontsize%, style$)
  {{Cl|DO}}
     {{Cl|_FONT}} font&
     style$ = "MONOSPACE"
    {{Cl|PRINT}}
    {{Cl|INPUT}} "Enter A FONT Size 8 {{Cl|TO}} 25: ", fontsize%
  {{Cl|LOOP}} {{Cl|UNTIL}} fontsize% > 7 and fontsize% < 26
  {{Cl|DO}}
     {{Cl|PRINT}}
    {{Cl|INPUT}} "Enter (0) for REGULAR {{Cl|OR}} (1) for ITALIC FONT: ", italic%
  {{Cl|LOOP}} {{Cl|UNTIL}} italic% = 0 or italic% = 1
  {{Cl|DO}}
     {{Cl|PRINT}}
     {{Cl|PRINT}}
     {{Cl|INPUT}} "Enter (0) for REGULAR {{Cl|OR}} (1) for BOLD FONT: ", bold%
     {{Cl|PRINT}} {{Text|<nowiki>"This is your LUCON font! Want to try another STYLE?(Y/N): "</nowiki>|#FFB100}};
  {{Cl|LOOP}} {{Cl|UNTIL}} italic% = 0 or italic% = 1
    {{Cl|DO}}: {{Cl|SLEEP}}: K$ = {{Cl|UCASE$}}({{Cl|INKEY$}}): {{Cl|DO...LOOP|LOOP UNTIL}} K$ = {{Text|<nowiki>"Y"</nowiki>|#FFB100}} {{Cl|OR (boolean)|OR}} K$ = {{Text|<nowiki>"N"</nowiki>|#FFB100}}
  {{Cl|IF}} italic% = 1 {{Cl|THEN}} style$ = style$ + ", ITALIC"
{{Cl|DO...LOOP|LOOP UNTIL}} K$ = {{Text|<nowiki>"N"</nowiki>|#FFB100}}
  {{Cl|IF}} bold% = 1 then style$ = style$ + ", BOLD"
 
  {{Cl|GOSUB}} ClearFont
  font& = {{Cl|_LOADFONT}}(fontpath$, fontsize%, style$)
  {{Cl|_FONT|_FONT }}font&
  {{Cl|PRINT}}
  {{Cl|PRINT}} "This is your LUCON font! Want to try another STYLE?(Y/N): ";
  {{Cl|DO}}: {{Cl|SLEEP}}: K$ = {{Cl|UCASE$}}({{Cl|INKEY$}}): {{Cl|LOOP}} {{Cl|UNTIL}} K$ = "Y" {{Cl|OR}} K$ = "N"
{{Cl|LOOP}} {{Cl|UNTIL}} K$ = "N"
{{Cl|GOSUB}} ClearFont
{{Cl|GOSUB}} ClearFont


{{Cl|PRINT}} "This is the QB64 default {{Cl|_FONT|_FONT }}16!"
{{Cl|PRINT}} {{Text|<nowiki>"This is the QB64 default _FONT 16!"</nowiki>|#FFB100}}
{{Cl|END}}
{{Cl|END}}


ClearFont:
ClearFont:
{{Cl|IF}} font& > 0 {{Cl|THEN}}
{{Cl|IF}} font& > {{Text|0|#F580B1}} {{Cl|THEN}}
     {{Cl|_FONT|_FONT }}16  'select inbuilt 8x16 default font
     {{Cl|_FONT}} {{Text|16|#F580B1}} {{Text|<nowiki>'select inbuilt 8x16 default font</nowiki>|#919191}}
     {{Cl|_FREEFONT}} font&
     {{Cl|_FREEFONT}} font&
{{Cl|END IF}}
{{Cl|END IF}}
{{Cl|RETURN}}
{{Cl|RETURN}}
{{CodeEnd}}
{{CodeEnd}}
'''NOTE:''' [[ENVIRON$]]("SYSTEMROOT") returns a string value of: "C:\WINDOWS". Add the "\FONTS\" folder and the '''.TTF''' font file name.
'''NOTE:''' [[ENVIRON$]]("SYSTEMROOT") returns a string value of: "C:\WINDOWS". Add the "\FONTS\" folder and the '''.TTF''' font file name.





Latest revision as of 10:16, 29 March 2023

The _FONT statement sets the current _LOADFONT function font handle to be used by PRINT.


Syntax

_FONT fontHandle&[, imageHandle&]


Parameters

  • fontHandle& is the handle retrieved from _LOADFONT function, the _FONT function, or a predefined handle.
  • If the image handle is omitted the current image _DESTination is used. Zero can designate the current program SCREEN.


Description

  • Predefined QB64 font handle numbers can be used before freeing a font:
    • _FONT 8 - default font for SCREEN 1, 2, 7, 8 or 13
    • _FONT 14 - default font for SCREEN 9 or 10
    • _FONT 16 - default font for SCREEN 0 (WIDTH 80, 25 text only), 11 or 12
    • _FONT 9, 15 and 17 are the double width versions of 8, 14 and 16 respectively in text SCREEN 0 only.
  • Unicode characters can be assigned to a monospace font that contains those unicode characters using the _MAPUNICODE TO ASCII mapping statement. The optional IME cyberbit.ttf font included with QB64 can also be used.
  • Can alpha blend a font with a background screen created by _NEWIMAGE in 32 bit color.
  • Check for valid handle values greater than 0 before using or freeing font handles.
  • Free unused font handles with _FREEFONT. Freeing invalid handles will create an "illegal function call" error.
  • NOTE: SCREEN 0 can only use one font type and style per viewed SCREEN page. Font size may also affect the window size.


Examples

Example: Previewing a font in SCREEN 0. A different true type font can be substituted below.

fontpath$ = ENVIRON$("SYSTEMROOT") + "\fonts\lucon.ttf" 'Find Windows Folder Path.
DO: CLS
    DO
        style$ = "MONOSPACE"
        PRINT
        INPUT "Enter A FONT Size 8 TO 25: ", fontsize%
    LOOP UNTIL fontsize% > 7 AND fontsize% < 26
    DO
        PRINT
        INPUT "Enter (0) for REGULAR OR (1) for ITALIC FONT: ", italic%
    LOOP UNTIL italic% = 0 OR italic% = 1
    DO
        PRINT
        INPUT "Enter (0) for REGULAR OR (1) for BOLD FONT: ", bold%
    LOOP UNTIL italic% = 0 OR italic% = 1
    IF italic% = 1 THEN style$ = style$ + ", ITALIC"
    IF bold% = 1 THEN style$ = style$ + ", BOLD"

    GOSUB ClearFont
    font& = _LOADFONT(fontpath$, fontsize%, style$)
    _FONT font&
    PRINT
    PRINT "This is your LUCON font! Want to try another STYLE?(Y/N): ";
    DO: SLEEP: K$ = UCASE$(INKEY$): LOOP UNTIL K$ = "Y" OR K$ = "N"
LOOP UNTIL K$ = "N"
GOSUB ClearFont

PRINT "This is the QB64 default _FONT 16!"
END

ClearFont:
IF font& > 0 THEN
    _FONT 16 'select inbuilt 8x16 default font
    _FREEFONT font&
END IF
RETURN

NOTE: ENVIRON$("SYSTEMROOT") returns a string value of: "C:\WINDOWS". Add the "\FONTS\" folder and the .TTF font file name.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link