UPRINTSTRING: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
mNo edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:_UPRINTSTRING}} | {{DISPLAYTITLE:_UPRINTSTRING}} | ||
The | 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&}}] | ||
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. | ||
{{PageDescription}} | {{PageDescription}} | ||
Line 25: | Line 26: | ||
** 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|''' | 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 38: | ||
File:Osx.png|'''yes''' | File:Osx.png|'''yes''' | ||
</gallery> | </gallery> | ||
{{PageExamples}} | {{PageExamples}} | ||
;Example 1:Centers and prints a Russian text on a graphics screen. | |||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|OPTION}} {{Cl|_EXPLICIT}} | {{Cl|OPTION}} {{Cl|_EXPLICIT}} | ||
Line 84: | Line 87: | ||
{{CodeEnd}} | {{CodeEnd}} | ||
---- | |||
;Example 2:Prints multiple lines of text using a recommended line gap. | |||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|OPTION}} {{Cl|_EXPLICIT}} | {{Cl|OPTION}} {{Cl|_EXPLICIT}} | ||
Line 116: | Line 121: | ||
{{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}} | ||
Line 124: | Line 130: | ||
* [[_SCREENIMAGE]], [[_SCREENPRINT]] | * [[_SCREENIMAGE]], [[_SCREENPRINT]] | ||
* [[Text Using Graphics]] | * [[Text Using Graphics]] | ||
{{PageNavigation}} | {{PageNavigation}} |
Revision as of 20:34, 3 May 2023
The _UPRINTSTRING statement prints ASCII / UNICODE text strings using graphic column and row coordinate positions.
Syntax
- _UPRINTSTRING (column, row), textExpression$[, maxWidth&][, utfEncoding&][, fontHandle&]
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.
Description
- The starting coordinate sets the top left corner of the text to be printed. Use _UFONTHEIGHT to calculate that text or font position
- _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.
- If the utfEncoding& is omitted, then it is assumed to be 0.
- All multi-byte UTF encodings are expected in little-endian.
- Unicode byte order mark (BOM) is not processed and must be handled by user code.
- 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 (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.
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
- _UPRINTWIDTH, _UFONTHEIGHT, _ULINESPACING
- _NEWIMAGE, _PRINTWIDTH, _PRINTMODE
- _CONTROLCHR
- _FONT, _LOADFONT, _FONTHEIGHT, _FONTWIDTH
- _SCREENIMAGE, _SCREENPRINT
- Text Using Graphics