Bitmap fonts in Qt Quick QML - qt

I've a png bitmap with many "glyphs" drawn one after another and a text file that relates an ascii number with a position and size in this bitmap. The glyphs are hand-drawn using different colors and transparency levels.
Somehow I need to open and use this font on QML. Unfortunately, it seems QML does not support bitmapped fonts "as is".
Is there any solution?

I've worked on the solution some days after posting this question. Since then, it seems there are lots of people still trying to use "old-school" bitmap fonts in Qt Quick. The solution I found is really elegant and has extremely good performance.
import QtQuick 1.1
Row {
property string text: ""
Repeater {
model: text.length
Image {
source: "bitmapfont/" + text.charCodeAt(index) + ".png"
}
}
}
Save as “TextBitmap.qml” in the same directory with your other qml code and then create a sub-directory called as the font name (“bitmapfont” in this example). You’ll need to draw or cut each bitmap font glyph individually and store them in that subfolder as a separate .png whose name is the Unicode of that glyph; for example bitmapfont/65.png for character ‘A’, bitmapfont/66.png for character ‘B’ and so on.
When this custom TextBitmap element is rendered for the first time –or anytime the text property is changed– Repeater will automatically create an image element for each character in text, each displaying the corresponding .png from “bitmapfont”.
Use it like this:
import QtQuick 1.1
Rectangle {
width: 800
height: 500
TextBitmap {
text: "Hello Bitmap Fonts!"
}
}
In http://www.royconejo.com/bitmap-fonts-in-qt-quick-qml/ you will find a more elaborated TextBitmap element, a video of how it looks and even a sample project.
I hope it helps someone!

This is not directly possible using Qt's font infrastructure: there is no support for bitmapped fonts. You can use QFontDatabase::addApplicationFronFromData, but then your font must be available as a TrueType font or a TrueType font collection.
The workarounds would be to.
Render the "text" using such a font into a QImage and show that using QML. This is OK if the text is static and doesn't change often.
Render the "text" using QQuickPaintedItem.

Related

a-text component not support Arabic text

no support for Arabic text in a-text component, also all the A-Frame’s built-in fonts doesn't support Arabic.
a-frame v: 0.6 ,
testing in Chrome ,
Mac
You can either:
1. use a custom font, by pointing a url to the .fnt file ( and the .png font file) as described in the documentation. Its done by simply defining
font:urlto.fntfile;fontImage:urlto.pngfile in the text component or primitive.
2. As described in the docs, rendering 2D text is no easy task, so You could make a transparent image containing Your text in arabic.
(2) Seems to be simpler, but it's a pain when You need to change a typo, or sth in the text. I use it for Polish characters anyway.
You will need to generate a custom font from a fontset that contains Arabic characters. In WebGL, we don't get fonts for free, they are converted into glyphs and vertices.
https://aframe.io/docs/0.6.0/components/text.html#custom-fonts
A more recent component aframe-troika-text provides a simpler solution that can render directly from a referenced font file.
https://github.com/lojjic/aframe-troika-text

UTF-8 Character in CSS

I have been using an html template that contains a slider (revolution slider - https://revolution.themepunch.com/)
It has a right and left arrow for navigating that use the following -
.tp-rightarrow.preview4:after { content: '\E824'; }
.tp-leftarrow.preview4:after { content: '\E825'; }
This works fine locally, but when I uploaded as part of an Umbraco site the two arrows changed to Chinese symbols. When I googled I found the following -
http://www.utf8icons.com/character/59429/UTF-8-character
I have now changed the CSS to display a > and < symbol but I'd like to know why the original code sometimes displays arrows and sometime displays chinese symbols.
Thanks.
U+E824 and ..25 are code points in the private use area. Code points in that area are not reserved, they do not have any pre-defined meaning. They are neither defined as Chinese characters nor arrows. You are free to use any private use code point for any purpose you wish, as long as the publisher and the client are in agreement what these code points mean.
In the browser this pretty much just boils down to having the right fonts installed/loaded/defined. In a web page, each character is simply rendered by the first defined/responsible font which happens to contain a glyph for that code point. The reason why it renders differently on two different systems/environments therefore can only stem from the fact that the CSS font definitions differ, or that the browser has different fonts installed.
Most likely the original included a custom web font which defined these characters as arrows. You have either omitted that font, or you have overridden the font precedence and made a different font apply to that element, and that font happens to define Chinese characters at those code points.

Webfonts for Asian Typefaces

I'm writing a simple site, but want to display Asian characters (Korean).
I'm using Google's Noto Fonts, but realized that each one of the .otf files are over 4M. I'm trying to keep my site lean and fast, but noticed that my site takes <100 ms to load, until I add the custom font, which takes over 1.5 seconds.
I'm using very basic styling:
<style type="text/css">
#font-face {
font-family: NotoSans;
src: url("/assets/fonts/NotoSansKR-Medium.otf") format("opentype");
}
pre {
font-family: NotoSans;
}
</style>
I looked into Compressing fonts for using in web, but I really want my site to be back to <100ms again without sacrificing aesthetics.
I thought of using something like Google Web Fonts, but couldn't find anything for Asian typefaces (maybe I'm not looking hard enough?). I also thought of caching, but that would work best with something like a webfont, which I cannot find. I looked on a popular Korean site, naver.com and I think they just use Dotum font (which is pretty good, but assumes the user has Dotum).
CSS from naver:
font-family: "돋움",Dotum,Helvetica,"Apple SD Gothic Neo",Sans-serif;
What is the best practice for providing a good typeface to users that want to read a bit of Korean text? I just want to personally be able to access my site without having to wait a whole 1.6+ seconds before any text shows up.
(I'm also curious what to do about french, but that is another issue)
Almost any font you include is going to push you over your speed specs. Let me suggest an alternative.
Set Dotum as your default font.
Test if Dotum is installed on the user's system.
Optionally test Helvetica and maybe Arial Unicode, as well.
Download the Noto font if the user does not have any of these fonts installed.
How to Test
There's no formal API to determine whether or not a font is installed, but a common solution is exemplified here. Basically, you set up a dummy element with a large font (monospace is popular but optional), set up a second dummy element with your desired font (using monospace as a fallback), and then compare the widths of the two to see whether your desired font successfully loaded.
Here's his code, but you can find similar solutions with a bit of searching (many of which don't use canvas, if browser support is a concern):
// Call this function and pass in the name of the font you want to check for availability.
//
function doesFontExist(fontName) {
// creating our in-memory Canvas element where the magic happens
var canvas = document.createElement("canvas");
var context = canvas.getContext("2d");
// the text whose final pixel size I want to measure
var text = "abcdefghijklmnopqrstuvwxyz0123456789";
// specifying the baseline font
context.font = "72px monospace";
// checking the size of the baseline text
var baselineSize = context.measureText(text).width;
// specifying the font whose existence we want to check
context.font = "72px '" + fontName + "', monospace";
// checking the size of the font we want to check
var newSize = context.measureText(text).width;
// removing the Canvas element we created
delete canvas;
//
// If the size of the two text instances is the same, the font does not exist because it is being rendered
// using the default sans-serif font
//
if (newSize == baselineSize) {
return false;
} else {
return true;
}
}
Download your font if necessary
From there you can simply apply the Noto font if no other font seems to be installed. You can do that easily enough using Javascript or jQuery, but I'm a big fan in general of jss, which allows for fast and easy on-the-fly style modifications.
A Bit about French
Finally, I don't think you'll encounter these same problems if you want to use French text. Latin Extended is ubiquitous, and the Unicode code blocks that include the combining accents used in French are included in a number of fonts. If you are especially concerned, you can include any number of lightweight fonts from Google Fonts or Typekit that include Latin Extended and/or the accent blocks.

CSS: font-family, if not one font, then none at all

So, I know that this isn't something that is normally a good idea for a website, but I have a special purpose/intent for such a use:
I have a multilingual dictionary that I'm working with online, where I need one of the languages to be in a specific font, from a file that I specify locally. However, I want this language to be rendered ONLY in this font, as if it is rendered using any other font, it will render incorrectly. That's all fine and dandy, and I can load the file in CSS and whatnot.
But I want to make it so that if it can't load that file, either for one reason or another, or something goes wrong, it can't go to another font. Basically, render this text using this font, and if you can't do that, don't just try and render it with Arial or whatever is the default -- show me blocks, show me a stark something.
I've spent a bit looking around, but am not sure what in CSS I would be using for this. Suggestions/help? Thanks :)
As an update to this question, since April 2013 there exists the Adobe Blank Font, which can be used for that purpose.
You may build a cross-browser css with FontQuirrel WebfontGenerator and the Adobe Blank font files.
If you just need the font in OpenType format you can use this single css file with the already embedded font
You can't do this. Text is text and text has to have a font that it is to be rendered in. If you really want, there's probably some weird JavaScript function that can detect the actual font being used for the text and if it doesn't match the one you want, then you can hide it or something. But in the end, your only option is to have the text displayed in some obscure font, or completely hide the text. If the text is visible, it has to be rendered using some font.
You could also theoretically create your own font where all the characters are just blank, but that seems highly illogical and such a waste of resources to make people download a font just so it can display meaningless emptiness.
There is no "don't render fonts" option. It's a font, it needs to be rendered, or else it's hidden visually in the DOM.
You could use Javascript to find out the font being applied to a certain block, and if it's not the font you want, just hide it. Or display a message.
Another solution is somehow specify the content to be empty. For example, I'm trying to override the +/- character that a Webix tree displays using Font Awesome:
#lhn-tree-container .webix_tree_open:before {
content: '';
}
This only works with the :before and :after pseudo-elements though.

Internet Explorer CSS Line Height For MusiSync Font

I'm trying to use the MusiSync font to embed a sharp and flat symbol in a line of text. In order to keep these symbols from being tiny I have to make their point size twice the size of the rest of the text. Unfortunately, this messes up the line height in Internet Explorer and I cannot find a way to control it. You can download the MusiSync font at:
http://www.icogitate.com/~ergosum/fonts/musicfonts.htm
My attempt to use this font in a web page can be found at:
http://www.williamsportwebdeveloper.com/MusiSync.htm
I opened up Photoshop and used the font you link to. There is a huge amount of white-space above each glyph in the font itself. The font is poorly designed.
If you set your style to this, you'll see the issue:
.style2 {
font-family: MusiSync;
font-size: 24pt;
border:1px solid #000000;
}
The problem appears in FireFiox 3 as well, its just manifesting itself a little differently.
You may be able to hack your way around this somehow, but it's going to be ugly. Unless you're using a lot of different font sizes, you may be better of using images.
Seeing that you are trying to use a very uncommon font, why not implement sIFR?
It will (possibly) solve some of your line height issues as well.
Read up here.
sIFR is an excellent choice for non-standard fonts.
You embed the font in a flash movie (don't worry most of the work is done for you) and add a bit of code to your page and the sIFR javascript will replace classes/id/tags etc with a flash movie containing the text/font that you're aiming for:
From http://www.mikeindustries.com/blog/sifr/
A normal (X)HTML page is loaded into the browser.
A javascript function is run which first checks that Flash is installed and then looks for whatever tags, ids, or classes you designate.
If Flash isn’t installed (or obviously if javascript is turned off), the (X)HTML page displays as normal and nothing further occurs. If Flash is installed, javascript traverses through the source of your page measuring each element you’ve designated as something you’d like “sIFRed”.
Once measured, the script creates Flash movies of the same dimensions and overlays them on top of the original elements, pumping the original browser text in as a Flash variable.
Actionscript inside of each Flash file then draws that text in your chosen typeface at a 6 point size and scales it up until it fits snugly inside the Flash movie.
An excellent cross browser platform indepent solution for non-standard fonts.

Resources