Bug? MONOSPACE not working/supported on Kindle Fire HD

Turbo3

Active Member
Licensed User
Longtime User
My app uses the MONOSPACE font to display line drawings using the old IBM line drawing characters. This works great on other android devices but fails on the Kindle Fire HD.

The problem seems to be the space characters are too small and the line drawing characters are too wide. They should (and do on other Android devices) have the same spacing.

So is this a problem with Kindle or the interface between Kindle and B4A that specifies the font?

Here is a screenshot from the Kindle. I have inline tags that change the font to MONOSPACE just before the line drawing and switch back to the default proportional font after the line drawing. There also should not be any break in the vertical lines so even the line to line spacing is off. But I could live with that if the horizontal lined up correctly.

 

stevel05

Expert
Licensed User
Longtime User
You could try loading a different typeface from a file, that may give the consistency you require rather than relying on the manufacturers to implement the fonts consistently (although you wouldn't think it would be a problem). Although as the kindle comes from a book reading background, they may do the typesetting differently. You may be able to adjust the line spacing if necessary.

Out of curiosity, what should it look like?
 

Turbo3

Active Member
Licensed User
Longtime User
I did not know I could load my own font. Will need to look into that.

Is it possible to save a good font from say a Nexus and then use that one as my gold standard?

Here is what it looks like on a Nexus 7.

 

Turbo3

Active Member
Licensed User
Longtime User
So far no luck loading my own fonts. I am using the RichStrings library and it does not look like their .Typeface2 takes anything but system fonts.

Normally I select fonts with
B4X:
rs.Typeface2("monospace","{m}")
Where rs is Richstring type and {m} is the inline tag to select this font.

Anyone ever use loaded fonts with Richstrings? Any examples of working code?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User

Turbo3

Active Member
Licensed User
Longtime User
Yes, that is what I do.
B4X:
MonoFont = Typeface.LoadFromAssets("monoserif-regular.ttf")
Then to use the loaded font I give the RichString the TypeFace using the following.
B4X:
rs.Typeface2("MonoFont","{m}")
But the font I selected is not used by RichStrings. I know this because I selected a script font just to see if it would display script characters and it did not.

So I know how to load a font but how do I make RichStrings use it. What is the format to use with Typeface2? It asks for a "typefamily" string but all I have is the Typeface variable "MonoFont" which I loaded from the assets file.
 

Turbo3

Active Member
Licensed User
Longtime User
No, that will not work for this case. What I am displaying is a large help file created with a text editor outside the app. The app just reads the text file into a RichString which takes the embedded tags and converts them to color,size,font changes and line drawing characters. Then the RichString is assigned to a single label that is in a ScrollView. What gets displayed is under total control of the text file.

So there is no drawing or panels just a single label with hundreds of lines of help information.

What I think you are suggesting would be unworkable for a dynamic help file. You don't want to hand code every drawing.

Once you define the set of tags that get converted that is all you need to code in B4A. Everything else is done in a text editor and look very close to what will appear on the help screen. Even the character line drawings are for the most part one for one since it is mono space and look close to how they will appear. You basically draw all the lines and text first for alignment then add the color tags latter as they will mess up the alignment.

Here is a sample of the raw text file.(It is a little better aligned than it shows here. Some spaces are too small so the vertical lines don't match up here on the display)
B4X:
The {D}Battery Status{D} screen can be divided into three sections: top, middle and bottom.{g}{m}
,___________________________, _,
|                           |  |Top
|  Battery Status Area      |  |Section
|___________________________| _:
|{Red},_________________________,{Red}| _,
|{Red}|                        |{Red}|  |Middle
|{Red}|                        |{Red}|  |Section
|{Red}|    Tap top half to     |{Red}|  |
|{Red}|                        |{Red}|  |
|{Red}|        zoom out        |{Red}|  |
|{Red}|                        |{Red}|  |
|{Red}|_________________________|{Red}|  |
|{Red}|                        |{Red}|  |
|{Red}|                        |{Red}|  |
|{Red}|  Tap bottom half to    |{Red}|  |
|{Red}|                        |{Red}|  |
|{Red}|        zoom in        |{Red}|  |
|{Red}|                        |{Red}|  |
|{Red}:_________________________:{Red}| _:
|___________________________| _,
|                          |  |Bottom
|  voltage range & temp    |  |Section
|___________________________| _:
|{Red},_______________,,________,{Red}|
|{Red}|Tap/Long Tap to||{Red} Status {Red}|{Red}|
|{Red}|{Red}[Dot1]{Red}Chg Scrn ||{Red}  Area  {Red}|{Red}|
|{Red}:_______________::________:{Red}|
:___________________________:
{m}{g}{D}Top Section{D} has the following information:
 

stevel05

Expert
Licensed User
Longtime User
This is a quick test using the RichString and RichStringBuilder Objects with a fixed width customfont, one I randomly downloaded which is included in the project file. It works on my Nexus7, it's not perfectly aligned, but that may be down to the quality of the font, see if it works on the Kindle.
 

Attachments

  • RST.zip
    29.3 KB · Views: 303

stevel05

Expert
Licensed User
Longtime User
And one using tokens
 

Attachments

  • RST1.zip
    29.3 KB · Views: 301

Turbo3

Active Member
Licensed User
Longtime User
Thanks for the test code.

Trouble is you are setting the entire label to that font. I need to be able to assign fonts just like you assigned colors. On a character by character basis not the entire label and inline not after they are loaded into the string. For that I need RichStrings' typeface2 function to take a loaded font which so far I have not been able to make work.

In your test code it also works (almost) on the Kindle if I just swap in the standard typeface.MONOSPACE instead of your external font. Vertical line horizontal spacing is perfect but there is a gap between lines. It is strange that the Kindle correctly handles the MONOSPACE horizontal spacing if applied at the label level but not within the label. This is leading me to believe this might be a RichStrings' problem since the MONOSPACE in Kindle seems ok at the full label level. I will have to play around some more with this.
 

Turbo3

Active Member
Licensed User
Longtime User
For the token version to match what I need you need to use a token to set the font instead of directly setting the whole label to the font.

Setting it directly to the font works but is not what I need. That would mean all my help text would be in monospace too.
 

stevel05

Expert
Licensed User
Longtime User
You could set the LabelFont to the CustomFont then use the tags to switch in the default/Standard fonts. That works without a problem. Just the other way round.
 
Last edited:

Turbo3

Active Member
Licensed User
Longtime User
When you say "That works without a problem" what is that based on? Have you got code that works on a Kindle?

I think that is what I am and have been doing and it does not work on a Kindle.

If you have a working example that would be great.
 

stevel05

Expert
Licensed User
Longtime User
I don't have a kindle to try it on, but you can use the font assignments to change it from and back to the monospaced font to the the android default fonts by using the Typeface2 method.

Try this one on the kindle.

If that just leaves the vertical spacing issues, I think there is a way to change the line spacing.
 

Attachments

  • RST2.zip
    29.3 KB · Views: 321

stevel05

Expert
Licensed User
Longtime User
You can use JavaObject to change the line spacing:

B4X:
    Dim Label1JO As JavaObject = Label1
    Dim Add As Float = 0
    Dim Mult As Float = 0.9
    Label1JO.RunMethod("setLineSpacing",Array(Add,Mult))

You should be able to get rid of the vertical line spacing issue with this. Try changing the multiplier.
 

Turbo3

Active Member
Licensed User
Longtime User
New tests show that the monospace problem on Kindle only happens when I replace the placeholder characters (' " + , : # - _ ) with the actual box characters (┌ ┐ └ ┘ ├ ┤ ┬ ┴ ┼ │ ─ ╵ ╷). When that happens the horizontal spacing gets messed up.

Strange that this only happens on the Kindle. These line graphic characters are above 0x7F so can not be read in by B4A into a string. So the text file has place holders that then get replaced for the corners and other box characters.

Thanks for the LineSpacing code it works on the Kindle but again strange that it is not needed on any other Android device to get the vertical lines to meet.

So for now I will just test for Kindle and disable the character replacement code.

Now how to detect only Kindles.
 

stevel05

Expert
Licensed User
Longtime User
Yes it seems strange that it only happens on Kindles, have you tried measuring the width of the characters, both the placeholders and the box characters? Mono spaced should mean just that, but apparently not. If different sizes are reported, it may give you a sign that you can't use the replacements.
 

Turbo3

Active Member
Licensed User
Longtime User
Excellent idea. Here are the results from Kindle and Nexus 7 with default.monospace & textsize=12.

On Kindle sp=11, i=11, W=11, ─=18, │=18

On Nexus sp=10,i=10, W=10, ─=10, │=10

Using the external font unispace.ttf the results are:

On Kindle sp=14, i=14, W=14, ─=13, │=13

On Nexus sp=12,i=12, W=12, ─=10, │=10


So this explains why when I swap in the box characters on Kindle things get messed up.

On Kindle the box characters are much wider with monospace and a little smaller with the external font.

The external font is also not monofont on the Nexus with the box characters being a little smaller.

Anyway, I have my test now. If the standard characters and box characters are not the same size then skip swapping in the box characters.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…