Private Sub Button1_Click
TextEngine.Initialize(Activity)
BBC.TextEngine = TextEngine
BBC.Text = _
$"
123456789*123456789*123456789*123456789*12345678
Hola, mundo ÑÑÑñññññññññññññññññññññññññññññññññ
ÁÉÍÓÚ €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€
111111111111111111111111111111111111111111111111
222222222222222222222222222222222222222222222222
333333333333333333333333333333333333333333333333
444444444444444444444444444444444444444444444444
555555555555555555555555555555555555555555555555
666666666666666666666666666666666666666666666666
777777777777777777777777777777777777777777777777
888888888888888888888888888888888888888888888888
999999999999999999999999999999999999999999999999
000000000000000000000000000000000000000000000000
123456789*123456789*123456789*123456789*12345678
________________________________________________
------------------------------------------------
123456789*123456789*123456789*123456789*12345678
================================================
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
çÇñÑáéíóúçÇñÑáéíóúçÇñÑáéíóúçÇñÑáéíóúçÇñÑáéíóúçÇñ
================================================
123456789*123456789*123456789*123456789*12345678
"$
End Sub
My FriendHi, I am trying to use a BCTextEngine to store text that I will then save as an image and finally print on bluetooth ticket printer.
I need the width to be always 48 columns.
For this I am using the type "Monospace", however I have a surprise, and that is that not all characters are monospace.
Considering that the maximum width is 48 columns, how can I get all the rows to have the same width?
I am attaching some screenshots so that you can understand the problem:
View attachment 143898
B4X:Private Sub Button1_Click TextEngine.Initialize(Activity) BBC.TextEngine = TextEngine BBC.Text = _ $" 123456789*123456789*123456789*123456789*12345678 Hola, mundo ÑÑÑñññññññññññññññññññññññññññññññññ ÁÉÍÓÚ €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€ 111111111111111111111111111111111111111111111111 222222222222222222222222222222222222222222222222 333333333333333333333333333333333333333333333333 444444444444444444444444444444444444444444444444 555555555555555555555555555555555555555555555555 666666666666666666666666666666666666666666666666 777777777777777777777777777777777777777777777777 888888888888888888888888888888888888888888888888 999999999999999999999999999999999999999999999999 000000000000000000000000000000000000000000000000 123456789*123456789*123456789*123456789*12345678 ________________________________________________ ------------------------------------------------ 123456789*123456789*123456789*123456789*12345678 ================================================ xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx çÇñÑáéíóúçÇñÑáéíóúçÇñÑáéíóúçÇñÑáéíóúçÇñÑáéíóúçÇñ ================================================ 123456789*123456789*123456789*123456789*12345678 "$ End Sub
The result is not correct, all the rows should have the same width, because they have 48 characters each:
View attachment 143899
Dim lines As String = _
$"
123456789*123456789*123456789*123456789*12345678
Hola, mundo ÑÑÑñññññññññññññññññññññññññññññññññ
ÁÉÍÓÚ €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€
111111111111111111111111111111111111111111111111
222222222222222222222222222222222222222222222222
333333333333333333333333333333333333333333333333
444444444444444444444444444444444444444444444444
555555555555555555555555555555555555555555555555
666666666666666666666666666666666666666666666666
777777777777777777777777777777777777777777777777
888888888888888888888888888888888888888888888888
999999999999999999999999999999999999999999999999
000000000000000000000000000000000000000000000000
123456789*123456789*123456789*123456789*12345678
________________________________________________
------------------------------------------------
123456789*123456789*123456789*123456789*12345678
================================================
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
çÇñÑáéíóúçÇñÑáéíóúçÇñÑáéíóúçÇñÑáéíóúçÇñÑáéíóúçÇñ
================================================
123456789*123456789*123456789*123456789*12345678
"$
Dim lbl As Label: lbl.initialize("")
lbl.SingleLine = False
Dim lblx As B4XView = lbl
Root.AddView(lblx, 0, 0, Root.Width, Root.Height)
Dim cs As CSBuilder: cs.Initialize
cs.Typeface(Typeface.MONOSPACE).Size(20)
Dim v() As String = Regex.Split(CRLF, lines)
For i = 0 To v.Length - 1
cs.Append(v(i)).Append(CRLF)
Next
cs.popAll
lblx.Text = cs
'Dim bmp As B4XBitmap = lblx.Snapshot
BBCodeView1.TextEngine.WordBoundaries = Chr(160) & TAB & CRLF & Chr(13)
Public Sub Test
BBCodeView1.TextEngine.Initialize(Root)
BBCodeView1.TextEngine.SpaceBetweenLines = DipToCurrent(12)
' BBCodeView1.TextEngine.MinGapBetweenLines = DipToCurrent(6)
' BBCodeView1.TextEngine.WordBoundaries = "&*+-/<>=\' :{}" & TAB & CRLF & Chr(13)
BBCodeView1.TextEngine.WordBoundaries = Chr(160) & TAB & CRLF & Chr(13)
Dim s As String = _
$"
123456789*123456789*123456789*123456789*12345678
Hola, mundo ÑÑÑñññññññññññññññññññññññññññññññññ
ÁÉÍÓÚ €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€
111111111111111111111111111111111111111111111111
222222222222222222222222222222222222222222222222
333333333333333333333333333333333333333333333333
444444444444444444444444444444444444444444444444
555555555555555555555555555555555555555555555555
666666666666666666666666666666666666666666666666
777777777777777777777777777777777777777777777777
888888888888888888888888888888888888888888888888
999999999999999999999999999999999999999999999999
000000000000000000000000000000000000000000000000
123456789*123456789*123456789*123456789*12345678
________________________________________________
------------------------------------------------
123456789*123456789*123456789*123456789*12345678
================================================
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
çÇñÑáéíóúçÇñÑáéíóúçÇñÑáéíóúçÇñÑáéíóúçÇñÑáéíóúçÇñ
================================================
123456789*123456789*123456789*123456789*12345678
"$
BBCodeView1.Text = s
TextArea1.Text = s
Dim html As String = _
$"
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: 'monospace';
font-size: 12px;
}
</style>
</head>
<body>
123456789*123456789*123456789*123456789*12345678<br>
Hola, mundo ÑÑÑñññññññññññññññññññññññññññññññññ<br>
ÁÉÍÓÚ €€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€<br>
111111111111111111111111111111111111111111111111<br>
222222222222222222222222222222222222222222222222<br>
333333333333333333333333333333333333333333333333<br>
444444444444444444444444444444444444444444444444<br>
555555555555555555555555555555555555555555555555<br>
666666666666666666666666666666666666666666666666<br>
777777777777777777777777777777777777777777777777<br>
888888888888888888888888888888888888888888888888<br>
999999999999999999999999999999999999999999999999<br>
000000000000000000000000000000000000000000000000<br>
123456789*123456789*123456789*123456789*12345678<br>
________________________________________________<br>
------------------------------------------------<br>
123456789*123456789*123456789*123456789*12345678<br>
================================================<br>
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx<br>
çÇñÑáéíóúçÇñÑáéíóúçÇñÑáéíóúçÇñÑáéíóúçÇñÑáéíóúçÇñ<br>
================================================<br>
123456789*123456789*123456789*123456789*12345678<br>
</body>
</html>
"$
WebView1.LoadHtml(html)
#if B4A
WebView1.ZoomEnabled = False
#End If
End Sub
The Euro is different (too narrow).
Brilliant! It was the space as a word boundary.
With the line (by @TILogistic) in post #9, it works. Without it doesn't.
In any case the OP can take it one step further, and see if his printer can print the image.
Fascinating, isn't it?
The chr(160) is the "á", what is the point of indicating that plus Tab?BBCodeView1.TextEngine.WordBoundaries = Chr(160) & TAB & CRLF & Chr(13)
BBCodeView1.TextEngine.WordBoundaries = TAB & CRLF & Chr(13)
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?