FONTHEIGHT: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Created page with "{{DISPLAYTITLE:_FONTHEIGHT}} The _FONTHEIGHT function returns the font height of a font handle created by _LOADFONT. {{PageSyntax}} :{{Parameter|pixelHeight%}} = _FONTHEIGHT[({{Parameter|fontHandle&}})] {{PageDescription}} * Returns the height of the last font used if a handle is not designated. * If no font is set it returns the current screen mode's text block height. {{PageExamples}} ''Example:'' Finding the font or text block size of pri...")
 
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{DISPLAYTITLE:_FONTHEIGHT}}
{{DISPLAYTITLE:_FONTHEIGHT}}
The [[_FONTHEIGHT]] function returns the font height of a font handle created by [[_LOADFONT]].
The [[_FONTHEIGHT]] function returns the font height of a font handle created by [[_LOADFONT]].




{{PageSyntax}}
{{PageSyntax}}
:{{Parameter|pixelHeight%}} = [[_FONTHEIGHT]][({{Parameter|fontHandle&}})]  
:{{Parameter|pixelHeight%}} = [[_FONTHEIGHT]][({{Parameter|fontHandle&}})]




Line 15: Line 14:
{{PageExamples}}
{{PageExamples}}
''Example:'' Finding the [[_FONT|font]] or text block size of printed [[STRING|string]] characters in graphic [[SCREEN]] modes.
''Example:'' Finding the [[_FONT|font]] or text block size of printed [[STRING|string]] characters in graphic [[SCREEN]] modes.
{{CodeStart}} '' ''
{{CodeStart}}
DO
{{Cl|DO}}
  {{Cl|INPUT}} "Enter Screen mode 1, 2 or 7 to 13 or 256, 32 for {{Cl|_NEWIMAGE}}: ", scr$
    {{Cl|INPUT}} {{Text|<nowiki>"Enter Screen mode 1, 2 or 7 to 13 or 256, 32 for _NEWIMAGE: "</nowiki>|#FFB100}}, scr$
  mode% = {{Cl|VAL}}(scr$)
    mode% = {{Cl|VAL}}(scr$)
{{Cl|LOOP}} {{Cl|UNTIL}} mode% > 0
{{Cl|DO...LOOP|LOOP UNTIL}} mode% > {{Text|0|#F580B1}}
{{Cl|SELECT CASE}} mode%
{{Cl|SELECT CASE}} mode%
  {{Cl|CASE}} 1, 2, 7 {{Cl|TO}} 13: {{Cl|SCREEN}} mode%
    {{Cl|CASE}} {{Text|1|#F580B1}}, {{Text|2|#F580B1}}, {{Text|7|#F580B1}} {{Cl|TO}} {{Text|13|#F580B1}}: {{Cl|SCREEN}} mode%
  {{Cl|CASE}} 256, 32: {{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(800, 600, mode%)
    {{Cl|CASE}} {{Text|256|#F580B1}}, {{Text|32|#F580B1}}: {{Cl|SCREEN}} {{Cl|_NEWIMAGE}}({{Text|800|#F580B1}}, {{Text|600|#F580B1}}, mode%)
  {{Cl|CASE ELSE}}: {{Cl|PRINT}} "Invalid mode selected!": {{Cl|END}}
    {{Cl|CASE ELSE}}: {{Cl|PRINT}} {{Text|<nowiki>"Invalid mode selected!"</nowiki>|#FFB100}}: {{Cl|END}}
{{Cl|END SELECT}}
{{Cl|END SELECT}}


{{Cl|INPUT}} "Enter first name of TTF font to use or hit enter for text block size: ", TTFont$
{{Cl|INPUT}} {{Text|<nowiki>"Enter first name of TTF font to use or hit enter for text block size: "</nowiki>|#FFB100}}, TTFont$
{{Cl|IF...THEN|IF}} {{Cl|LEN}}(TTFont$) {{Cl|THEN}} {{Cl|INPUT}} "Enter font height: ", hi$
{{Cl|IF}} {{Cl|LEN}}(TTFont$) {{Cl|THEN}} {{Cl|INPUT}} {{Text|<nowiki>"Enter font height: "</nowiki>|#FFB100}}, hi$
height& = {{Cl|VAL}}(hi$)
height& = {{Cl|VAL}}(hi$)
{{Cl|IF...THEN|IF}} height& > 0 {{Cl|THEN}}
{{Cl|IF}} height& > {{Text|0|#F580B1}} {{Cl|THEN}}
  fnt& = {{Cl|_LOADFONT}}("C:\Windows\Fonts\" + TTFont$ + ".ttf", height&, style$)
    fnt& = {{Cl|_LOADFONT}}({{Text|<nowiki>"C:\Windows\Fonts\"</nowiki>|#FFB100}} + TTFont$ + {{Text|<nowiki>".ttf"</nowiki>|#FFB100}}, height&, style$)
  {{Cl|IF...THEN|IF}} fnt& <= 0 {{Cl|THEN}} {{Cl|PRINT}} "Invalid Font handle!": {{Cl|END}}
    {{Cl|IF}} fnt& <= {{Text|0|#F580B1}} {{Cl|THEN}} {{Cl|PRINT}} {{Text|<nowiki>"Invalid Font handle!"</nowiki>|#FFB100}}: {{Cl|END}}
  {{Cl|_FONT}} fnt&
    {{Cl|_FONT}} fnt&
{{Cl|END IF}}
{{Cl|END IF}}


TextSize wide&, high& 'get the font or current screen mode's text block pixel size
{{Text|TextSize|#55FF55}} wide&, high& {{Text|<nowiki>'get the font or current screen mode's text block pixel size</nowiki>|#919191}}


{{Cl|_PRINTSTRING}} (20, 100), "Block size = " + {{Cl|CHR$}}(1) + {{Cl|STR$}}(wide&) + " X" + {{Cl|STR$}}(high&) + " " + {{Cl|CHR$}}(2)
{{Cl|_PRINTSTRING}} ({{Text|20|#F580B1}}, {{Text|100|#F580B1}}), {{Text|<nowiki>"Block size = "</nowiki>|#FFB100}} + {{Cl|CHR$}}({{Text|1|#F580B1}}) + {{Cl|STR$}}(wide&) + {{Text|<nowiki>" X"</nowiki>|#FFB100}} + {{Cl|STR$}}(high&) + {{Text|<nowiki>" "</nowiki>|#FFB100}} + {{Cl|CHR$}}({{Text|2|#F580B1}})


{{Cl|END}}
{{Cl|END}}


{{Cl|SUB}} TextSize (TextWidth&, TextHeight&)
{{Cl|SUB}} {{Text|TextSize|#55FF55}} (TextWidth&, TextHeight&)
TextWidth& = {{Cl|_PRINTWIDTH}}("W") 'measure width of one font or text character
    TextWidth& = {{Cl|_PRINTWIDTH}}({{Text|<nowiki>"W"</nowiki>|#FFB100}}) {{Text|<nowiki>'measure width of one font or text character</nowiki>|#919191}}
TextHeight& = {{Cl|_FONTHEIGHT}} 'can measure normal text block heights also
    TextHeight& = {{Cl|_FONTHEIGHT}} {{Text|<nowiki>'can measure normal text block heights also</nowiki>|#919191}}
{{Cl|END SUB}} '' ''
{{Cl|END SUB}}
{{CodeEnd}}
{{CodeEnd}}




{{PageSeeAlso}}
{{PageSeeAlso}}
* [https://qb64phoenix.com/forum/showthread.php?tid=1145 Featured in our "Keyword of the Day" series]
* [[_FONTWIDTH]], [[_FONT]]
* [[_FONTWIDTH]], [[_FONT]]
* [[_PRINTWIDTH]], [[_PRINTSTRING]]
* [[_PRINTWIDTH]], [[_PRINTSTRING]]

Latest revision as of 15:17, 25 September 2024

The _FONTHEIGHT function returns the font height of a font handle created by _LOADFONT.


Syntax

pixelHeight% = _FONTHEIGHT[(fontHandle&)]


Description

  • Returns the height of the last font used if a handle is not designated.
  • If no font is set it returns the current screen mode's text block height.


Examples

Example: Finding the font or text block size of printed string characters in graphic SCREEN modes.

DO
    INPUT "Enter Screen mode 1, 2 or 7 to 13 or 256, 32 for _NEWIMAGE: ", scr$
    mode% = VAL(scr$)
LOOP UNTIL mode% > 0
SELECT CASE mode%
    CASE 1, 2, 7 TO 13: SCREEN mode%
    CASE 256, 32: SCREEN _NEWIMAGE(800, 600, mode%)
    CASE ELSE: PRINT "Invalid mode selected!": END
END SELECT

INPUT "Enter first name of TTF font to use or hit enter for text block size: ", TTFont$
IF LEN(TTFont$) THEN INPUT "Enter font height: ", hi$
height& = VAL(hi$)
IF height& > 0 THEN
    fnt& = _LOADFONT("C:\Windows\Fonts\" + TTFont$ + ".ttf", height&, style$)
    IF fnt& <= 0 THEN PRINT "Invalid Font handle!": END
    _FONT fnt&
END IF

TextSize wide&, high& 'get the font or current screen mode's text block pixel size

_PRINTSTRING (20, 100), "Block size = " + CHR$(1) + STR$(wide&) + " X" + STR$(high&) + " " + CHR$(2)

END

SUB TextSize (TextWidth&, TextHeight&)
    TextWidth& = _PRINTWIDTH("W") 'measure width of one font or text character
    TextHeight& = _FONTHEIGHT 'can measure normal text block heights also
END SUB


See also



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