UPRINTSTRING: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
(Initial version)
 
(Add parameter imageHandle& doc)
 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:_UPRINTSTRING}}
{{DISPLAYTITLE:_UPRINTSTRING}}
The [[_UPRINTSTRING]] statement prints ASCII / UNICODE text [[STRING|strings]] using graphic column and row coordinate positions.
The '''_UPRINTSTRING''' statement prints ASCII / UNICODE text [[STRING|strings]] using graphic column and row coordinate positions.




{{PageSyntax}}
{{PageSyntax}}
: [[_UPRINTSTRING]]({{Parameter|column}}, {{Parameter|row}}), {{Parameter|textExpression$}}[, {{Parameter|maxWidth&}}][, {{Parameter|utfEncoding&}}][, {{Parameter|fontHandle&}}]
: [[_UPRINTSTRING]] ({{Parameter|column}}, {{Parameter|row}}), {{Parameter|textExpression$}}[, {{Parameter|maxWidth&}}][, {{Parameter|utfEncoding&}}][, {{Parameter|fontHandle&}}][, {{Parameter|imageHandle&}}]




Line 13: Line 13:
* {{Parameter|utfEncoding&}} is an optional UTF encoding of {{Parameter|textExpression$}}. This can be 0 for ASCII, 8 for UTF-8, 16 for UTF-16 or 32 for UTF-32.
* {{Parameter|utfEncoding&}} is an optional UTF encoding of {{Parameter|textExpression$}}. This can be 0 for ASCII, 8 for UTF-8, 16 for UTF-16 or 32 for UTF-32.
* {{Parameter|fontHandle&}} is an optional font handle.
* {{Parameter|fontHandle&}} is an optional font handle.
* {{Parameter|imageHandle&}} is the optional image or destination to use. Zero designates current [[SCREEN]] page.


{{PageDescription}}
{{PageDescription}}
* The starting coordinate sets the top left corner of the text to be printed. Use [[_UFONTHEIGHT]] to calculate that text or [[_FONT|font]] position
* The starting coordinate sets the top left corner of the text to be printed.
* [[_UPRINTWIDTH]] can be used to determine how wide a text print will be so that the screen width is not exceeded.
* If {{Parameter|maxWidth&}} is omitted, then the entire {{Parameter|textExpression$}} is rendered.
* Alternatively, {{Parameter|maxWidth&}} can be used to clip text rending after a certain amount of pixel width.
* If {{Parameter|utfEncoding&}} is omitted, then it is assumed to be 0 (ASCII).
* If the {{Parameter|utfEncoding&}} is omitted, then it is assumed to be 0.
* If {{Parameter|fontHandle&}} is omitted, then the current write page font is used.
* All multi-byte UTF encodings are expected in little-endian.
* [[_UPRINTWIDTH]] can be used to determine how wide a text print will be so that the screen width is not exceeded. Alternatively, {{Parameter|maxWidth&}} can be used to clip text rending after a certain amount of pixel width.
* Unicode byte order mark (BOM) is not processed and must be handled by user code.
* [[_ULINESPACING]] can be used to calculate the next [[_FONT|font]] vertical position.
* Unicode byte order mark (BOM) is not processed and must be handled by user code except for UTF-16.
* UTF-16 LE is assumed if BOM is absent in the string and {{Parameter|utfEncoding&}} is 16.
* Can use the current font alpha blending with a designated image background. See the [[_RGBA]] function example.
* Can use the current font alpha blending with a designated image background. See the [[_RGBA]] function example.
* Use the [[_PRINTMODE]] statement before printing to set how the background is rendered.
* Use the [[_PRINTMODE]] statement before printing to set how the background is rendered.
** Use the [[_PRINTMODE (function)]] to find the current _PRINTMODE setting.
** Use the [[_PRINTMODE (function)]] to find the current _PRINTMODE setting.
* SCREEN 0 (text only) mode is not supported. Attempting to use this in SCREEN 0 will generate an error.
* SCREEN 0 (text only) mode is not supported. Attempting to use this in SCREEN 0 will generate an error.


{{PageAvailability}}
{{PageAvailability}}
<!-- QB64 = a version or none, QBPE = a version or all, Platforms = yes or no -->
<!-- QB64 = a version or none, QBPE = a version or all, Platforms = yes or no -->
<gallery widths="48px" heights="48px" mode="nolines">
<gallery widths="48px" heights="48px" mode="nolines">
File:Qb64.png|'''no'''
File:Qb64.png|'''none'''
File:Qbpe.png|'''v3.7.0'''
File:Qbpe.png|'''v3.7.0'''
File:Apix.png
File:Apix.png
Line 36: Line 41:
File:Osx.png|'''yes'''
File:Osx.png|'''yes'''
</gallery>
</gallery>
<!-- additional availability notes go below here -->


{{PageExamples}}
{{PageExamples}}
''Example 1:'' Centers and prints a Russian text on a graphics screen.
;Example 1:Centers and prints a Russian text on a graphics screen.
{{CodeStart}}
{{CodeStart}}
{{Cl|OPTION}} {{Cl|_EXPLICIT}}
{{Cl|OPTION}} {{Cl|_EXPLICIT}}
Line 45: Line 52:


{{Cl|DIM}} fh {{Cl|AS}} {{Cl|LONG}}: fh = {{Cl|_LOADFONT}}({{Text|<nowiki>"cyberbit.ttf"</nowiki>|#FFB100}}, {{Text|21|#F580B1}})
{{Cl|DIM}} fh {{Cl|AS}} {{Cl|LONG}}: fh = {{Cl|_LOADFONT}}({{Text|<nowiki>"cyberbit.ttf"</nowiki>|#FFB100}}, {{Text|21|#F580B1}})
{{Cl|IF}} fh <= {{Text|0|#F580B1}} {{Cl|THEN}}
    {{Cl|PRINT}} {{Text|<nowiki>"Failed to load font file!"</nowiki>|#FFB100}}
    {{Cl|END}}
{{Cl|END IF}}


{{Cl|_FONT}} fh
{{Cl|_FONT}} fh
Line 80: Line 91:
{{CodeEnd}}
{{CodeEnd}}


''Example 2:'' Prints multiple lines of text using a recommended line gap.
----
 
;Example 2:Prints multiple lines of text using a recommended line gap.
{{CodeStart}}
{{CodeStart}}
{{Cl|OPTION}} {{Cl|_EXPLICIT}}
{{Cl|OPTION}} {{Cl|_EXPLICIT}}
Line 112: Line 125:
{{Cl|DATA}} {{Text|<nowiki>"To strive,to seek,to find,and not to yield."</nowiki>|#FFB100}}
{{Cl|DATA}} {{Text|<nowiki>"To strive,to seek,to find,and not to yield."</nowiki>|#FFB100}}
{{CodeEnd}}
{{CodeEnd}}


{{PageSeeAlso}}
{{PageSeeAlso}}
* [[_UPRINTWIDTH]], [[_UFONTHEIGHT]], [[_ULINESPACING]]
* [https://qb64phoenix.com/forum/showthread.php?tid=2765 Featured in our "Keyword of the Day" series (Part 1)]
* [https://qb64phoenix.com/forum/showthread.php?tid=2778 Featured in our "Keyword of the Day" series (Part 2)]
* [[_UPRINTWIDTH]], [[_UFONTHEIGHT]], [[_ULINESPACING]], [[_UCHARPOS]]
* [[_NEWIMAGE]], [[_PRINTWIDTH]], [[_PRINTMODE]]
* [[_NEWIMAGE]], [[_PRINTWIDTH]], [[_PRINTMODE]]
* [[_CONTROLCHR]]
* [[_CONTROLCHR]]
Line 120: Line 136:
* [[_SCREENIMAGE]], [[_SCREENPRINT]]
* [[_SCREENIMAGE]], [[_SCREENPRINT]]
* [[Text Using Graphics]]
* [[Text Using Graphics]]


{{PageNavigation}}
{{PageNavigation}}

Latest revision as of 21:45, 6 June 2024

The _UPRINTSTRING statement prints ASCII / UNICODE text strings using graphic column and row coordinate positions.


Syntax

_UPRINTSTRING (column, row), textExpression$[, maxWidth&][, utfEncoding&][, fontHandle&][, imageHandle&]


Parameters

  • column and row are INTEGER or LONG starting PIXEL (graphic) column and row coordinates to set text or custom fonts.
  • textExpression$ is any literal or variable string value of text to be displayed.
  • maxWidth& is an optional horizontal pixel limit after which the text rendering will be clipped.
  • utfEncoding& is an optional UTF encoding of textExpression$. This can be 0 for ASCII, 8 for UTF-8, 16 for UTF-16 or 32 for UTF-32.
  • fontHandle& is an optional font handle.
  • imageHandle& is the optional image or destination to use. Zero designates current SCREEN page.


Description

  • The starting coordinate sets the top left corner of the text to be printed.
  • If maxWidth& is omitted, then the entire textExpression$ is rendered.
  • If utfEncoding& is omitted, then it is assumed to be 0 (ASCII).
  • If fontHandle& is omitted, then the current write page font is used.
  • _UPRINTWIDTH can be used to determine how wide a text print will be so that the screen width is not exceeded. Alternatively, maxWidth& can be used to clip text rending after a certain amount of pixel width.
  • _ULINESPACING can be used to calculate the next font vertical position.
  • Unicode byte order mark (BOM) is not processed and must be handled by user code except for UTF-16.
  • UTF-16 LE is assumed if BOM is absent in the string and utfEncoding& is 16.
  • Can use the current font alpha blending with a designated image background. See the _RGBA function example.
  • Use the _PRINTMODE statement before printing to set how the background is rendered.
  • SCREEN 0 (text only) mode is not supported. Attempting to use this in SCREEN 0 will generate an error.


Availability


Examples

Example 1
Centers and prints a Russian text on a graphics screen.
OPTION _EXPLICIT

SCREEN _NEWIMAGE(800, 600, 32)

DIM fh AS LONG: fh = _LOADFONT("cyberbit.ttf", 21)
IF fh <= 0 THEN
    PRINT "Failed to load font file!"
    END
END IF

_FONT fh

RESTORE text_data
DIM myString AS STRING: myString = LoadUData$

_UPRINTSTRING (_WIDTH \ 2 - _UPRINTWIDTH(myString, 8, fh) \ 2, _HEIGHT \ 2 - _UFONTHEIGHT \ 2), myString, _WIDTH, 8

END

text_data:
DATA 6F,D0,91,D1,8B,D1,81,D1,82,D1,80,D0,B0,D1,8F,20,D0,BA,D0,BE,D1,80,D0,B8,D1
DATA 87,D0,BD,D0,B5,D0,B2,D0,B0,D1,8F,20,D0,BB,D0,B8,D1,81,D0,B0,20,D0,BF,D0,B5
DATA D1,80,D0,B5,D0,BF,D1,80,D1,8B,D0,B3,D0,B8,D0,B2,D0,B0,D0,B5,D1,82,20,D1,87
DATA D0,B5,D1,80,D0,B5,D0,B7,20,D0,BB,D0,B5,D0,BD,D0,B8,D0,B2,D1,83,D1,8E,20,D1
DATA 81,D0,BE,D0,B1,D0,B0,D0,BA,D1,83,2E

FUNCTION LoadUData$
    DIM AS _UNSIGNED LONG i, s
    DIM d AS STRING
    DIM buffer AS STRING

    READ d
    s = VAL("&h" + d)
    buffer = SPACE$(s)

    FOR i = 1 TO s
        READ d
        ASC(buffer, i) = VAL("&h" + d)
    NEXT

    LoadUData = buffer
END FUNCTION

Example 2
Prints multiple lines of text using a recommended line gap.
OPTION _EXPLICIT

SCREEN _NEWIMAGE(800, 600, 32)

DIM fh AS LONG: fh = _LOADFONT("LHANDW.TTF", 23)
IF fh <= 0 THEN
    PRINT "Failed to load font file!"
    END
END IF

_FONT fh

CLS , _RGB32(200, 200, 200)
COLOR _RGB32(0, 0, 0)
_PRINTMODE _KEEPBACKGROUND

DIM l AS STRING, i AS LONG
FOR i = 0 TO 4
    READ l
    _UPRINTSTRING (0, _ULINESPACING * i), l
NEXT

END

DATA "We are not now that strength which in old days"
DATA "Moved earth and heaven; that which we are,we are;"
DATA "One equal temper of heroic hearts,"
DATA "Made weak by time and fate,but strong in will"
DATA "To strive,to seek,to find,and not to yield."


See also



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