mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-09-01 16:20:17 +00:00
51 lines
2.3 KiB
Text
51 lines
2.3 KiB
Text
|
The {{KW|_PRINTWIDTH}} function returns the width in pixels of the [[_FONT]] or text [[STRING|string]] that a program will print.
|
||
|
|
||
|
|
||
|
|
||
|
{{PageSyntax}}
|
||
|
:{{Parameter|pixel_width}} = {{KW|_PRINTWIDTH}}({{Parameter|text_to_print$}}[, {{Parameter|destination_handle&}}])
|
||
|
|
||
|
|
||
|
{{PageDescription}}
|
||
|
* {{Parameter|text_to_print$}} is any literal or variable [[STRING]] value.
|
||
|
* If the {{Parameter|destination_handle&}} is omitted, the current destination image or screen page is used.
|
||
|
* Useful to find the width of the font print [[STRING|string]] before actually printing it.
|
||
|
* Can be used with '''variable''' width fonts or '''no font''' at all unlike [[_FONTWIDTH]] which requires MONOSPACE fonts only.
|
||
|
* '''_PRINTWIDTH cannot be used in SCREEN 0!'''
|
||
|
|
||
|
|
||
|
''Example:'' SUB returns font or screen mode's text block size using _PRINTWIDTH and [[_FONTHEIGHT]] without a handle parameter.
|
||
|
{{CodeStart}} '' ''
|
||
|
{{Cl|DO}}
|
||
|
{{Cl|INPUT}} "Enter Screen mode 1, 2 or 7 to 13: ", scr$
|
||
|
mode% = {{Cl|VAL}}(scr$)
|
||
|
{{Cl|LOOP}} {{Cl|UNTIL}} mode% > 0
|
||
|
{{Cl|SCREEN (statement)|SCREEN}} mode%
|
||
|
{{Cl|INPUT}} "Enter first name of TTF font to use or hit enter for text size: ", TTFont$
|
||
|
{{Cl|IF}} {{Cl|LEN}}(TTFont$) {{Cl|THEN}} {{Cl|INPUT (file mode)|INPUT}} "Enter font height: ", hi$
|
||
|
height& = {{Cl|VAL}}(hi$)
|
||
|
{{Cl|IF}} height& > 0 {{Cl|THEN}} {{Cl|_FONT}} {{Cl|_LOADFONT}}("C:\Windows\Fonts\" + TTFont$ + ".ttf", height&, style$)
|
||
|
|
||
|
TextSize wide&, high& 'get the font or current screen mode's text block pixel size
|
||
|
|
||
|
{{Cl|_PRINTSTRING}} (20, 100), {{Cl|CHR$}}(1) + {{Cl|STR$}}(wide&) + " X" + {{Cl|STR$}}(high&) + " " + {{Cl|CHR$}}(2)
|
||
|
|
||
|
{{Cl|END}}
|
||
|
|
||
|
{{Cl|SUB}} TextSize (TextWidth&, TextHeight&)
|
||
|
TextWidth& = {{Cl|_PRINTWIDTH}}("W") 'measure width of one font or text character
|
||
|
TextHeight& = {{Cl|_FONTHEIGHT}} 'can measure normal text block heights also
|
||
|
{{Cl|END SUB}} '' ''
|
||
|
{{CodeEnd}}
|
||
|
{{small|Code by Ted Weissgerber}}
|
||
|
<center>'''Note:''' The SUB procedure does not need the font handle for font sizes after [[_FONT]] enables one.</center>
|
||
|
|
||
|
|
||
|
{{PageSeeAlso}}
|
||
|
* [[_FONTWIDTH]], [[_FONTHEIGHT]]
|
||
|
* [[_NEWIMAGE]], [[_LOADFONT]]
|
||
|
* [[_PRINTSTRING]], [[_FONT]]
|
||
|
* [[Text Using Graphics]] (Demo)
|
||
|
|
||
|
|
||
|
{{PageNavigation}}
|