I use CreateTextLayout and CreateTextFormat to draw text with DirectWrite (C++), the text is mixed Hebrew/English, is there a way to use a different font/font size for the Latin and Hebrew characters?
Thanks.
When you create the IDWriteTextFormat using CreateTextFormat, you can pass the name of the font family in the first parameter and you can change the size of the font in sixth parameter.
You can get the CreateTextFormat parameters from MSDN.
Here is a list of Microsoft Windows font families, you will find ones in Latin and Hebrew there.
I ended up calling IDWriteFont::HasCharacter to build text ranges inside which all characters use the same font (the hebrew or the latin one).
If that text range uses the hebrew font, I call textLayout->SetFontSize on it to increase the font size.
This amounts to anticipating the font callback DirectWrite will do, which is automatic and cannot be customized.
Related
In the pluma editor (on Linux) and sometimes in a web browser, for unrecognized characters, I see a little box with the Unicode value inside. I have seen 4 digit and 6 digit code boxes.
I WANT these little boxes with numbers (as appropriate.) How do I get these to display in a C++ Qt program?
Can you get a two digit box?
Here is an example, as shown in the pluma editor:
These glyphs are produced by the default fallback font for the system/platform – they are not inherently a feature of Qt.
If you want all characters to be rendered this way, you can use the Unicode BMP Fallback font, which has glyphs for all code points in the basic multilingual plane as hex digits in a box.
I'd like to ask what's the simplest way of writing the chess unicode characters in a console window in C++? (♙♘♗♖♕♔♟♞♝♜♛♚) They are part of the "Miscellaneous Symbols" block in unicode. https://en.wikipedia.org/wiki/Chess_symbols_in_Unicode
I also want to print characters with square size, right now my chess board is not square, because each character is a rectangle and not a square.
It'd also be good to be able to write with ordinary non-square characters below the chess board, but that might be impossible? To mix different fonts/formattings in the same console window?
Ok, thanks in advance! :)
The first part of your question, outputting those characters, is platform-dependent. Linux consoles often use UTF-8, if that is the case you can encode the characters as UTF-8 and write them to standard output. On Windows you can use the Console API (the WriteConsole function):
HANDLE handle = GetStandardHandle(STD_OUTPUT_HANDLE);
DWORD written = 0;
// explicitly call the wide version (which always accepts UTF-16)
WriteConsoleW(handle, L"\u2658", 1, &written, NULL);
One caveat which is hard to work around is that you need a console font containing those characters.
For getting square cells, this is dependent on a lot of specifics about the way the console renders text. If it uses font substitution, then there is a chance the text will not actually be monospaced.
Now, if you have a console font with these characters, and if that font is monospaced, then you may be able to draw a square board by adding some spacing between the characters. You can use block elements like ▌ U+258C — LEFT HALF BLOCK to draw the chequerboard: ▌♘▐█▌ ▐.
I find have used both these functions before, but I don't quite see the the difference between them. Well, I know that DrawText requires a formatting rectangle,and can do some text formatting, and textout only the starting coordinates, are there any other differences?
DrawText
It draws a text string into a rectangle region specified in logical coordinates.
It provides convenient ways of formatting multiline text.
It is mainly used for
wordbreaking paragraph formatting, expanding tabs etc.
TextOut
It is a simple text-drawing function which is easy to use.
It draws a character string at a specified location, using the currently selected text attributes.
The text
string to draw does not need to be zero terminated.
Also, take a look at ExtTextOut and DrawTextEx
DrawText() is User32.dll
TextOut() is Gdi32.dll
DrawText most likely calls TextOut in its implementation.
Draw text can be used to just give the length or size of text without actually displaying it. This is useful when you have to fine the maximum display length of a set of strings. Also if you supply a null terminated string as the input in DrawText, it is not necessary to supply the length of the string - that is automatically created.
Take a look at this and this.
I'm rendering some text using pangomm, but the font that I am using doesn't have glyphs for parts of the text (in this case, there is some Japanese mixed in with English). Pango seems to render the text correctly using a fallback font.
How can I determine which font is being used as the fallback?
Actually the font selection is based on the selected Pango font backend. Mostly used (I think) is Fontconfig.
You fonts are basically always chosen by looking at the fonts Unicode coverage, meaning that Fontconfig tries to choose the font that covers the letters in the text you want to render best.
Not knowing if your problem applies to Fontconfig, I won't go into to much detail. But if so, have a look at http://www.freedesktop.org/software/fontconfig/fontconfig-user.html, especially the section on 'font matching'.
Feel free to ask again.
I'm working on my edit box that I'm creating. I need to find a font that draw letter at same size. I'm using directx
I'm guessing that by "find a font that draw letter at same size" you mean a font where all of the letters are the same size. This is called a Monospaced or Fixed Width Font. There should be several on most systems, the one that you should be able to count on always existing on Windows systems is "Courier New".