1
1
Fork 0
mirror of https://github.com/QB64Official/qb64.git synced 2024-07-05 20:30:25 +00:00
qb64/internal/help/_PRINTWIDTH.txt

53 lines
2.5 KiB
Plaintext
Raw Normal View History

2016-03-18 11:36:04 +00:00
{{DISPLAYTITLE:_PRINTWIDTH}}{{DISPLAYTITLE:}}
The [[_PRINTWIDTH]] function returns the width in pixels of the [[_FONT]] or text [[STRING|string]] that a program will print.
{{PageSyntax}}
2016-03-18 11:36:04 +00:00
::: pixel_width = '''_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.
2016-03-18 11:36:04 +00:00
* '''_PRINTWIDTH cannot be used in SCREEN 0 in QB64-SDL version.'''
* '''QB64-GL''' does support SCREEN 0 use of _PRINTWIDTH which will return the character length of text exactly as [[LEN]](text$) would.
''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}}