I'm trying to build a Prisoner's Dilemma game in Z-Tree (the toolkit for building game theory experiments), and have encountered two irritating problems.
I haven't succeeded in applying formatting to the output inside of an item. Specifically, I'd like to display the number of years of prison each player gets at the end of a game, in the format:
Years of Prison: value
using the Layout dialogue of the Item box. Not using the layout and inserting the values directly into the text leads to a far too messy display.
Is there a way to do that using variables (conceptually, something like Payoff = {\rtf \fs30 Payoff}), and not concrete values (like !text: 1 = {\rtf \fs30 1}).
Is there a way to enable UTF-8 encoding? I have some letters (like č or š) which aren't being displayed correctly?
I'm using the latest Z-Tree version, on Linux ElementaryOS, running on Wine.
Answer to 1: In the label of your item, do this:
<>{\rtf Payoff = \fs30 <Payoff|0.1> }
Answer to 2: I do not know for sure. I think the font z-Tree uses by default does not support those characters. What I would try is to find a font that supports them and use it. In your code the characters will appear as weird symbols, but maybe in the leafs they'll be displayed correctly.
Is it possible to display fractions in a gtk widget like GtkTextView, presumably via using pango markup? I'm looking for something which is possible to edit by a user, so e.g. a pixbuf with a rendered png file is not ok.
Also I need arbitrarily long enumerators and denominators so
<sup>a</sup>/<sub>b</sub>
is not acceptable.
No, that's not possible. I don't know what your use case is, but to make an editable horizontal fraction (as in $\frac{a}{b}$) I would suggest doing something like putting two GtkEntry widgets without borders into a grid, and draw a line between them (or use a GtkSeparator.) You could even embed this grid inside a GtkTextView if you needed it to be inline.
I noticed this problem using Qt libraries, but, to be honest, than I found that is a global OS X issue. I have a music font, say the classic Petrucci.ttf or Marl.ttf... As I put characters using QPainter::drawText() function, I can see only standard letters.
Also this happens using asian fonts or other symbolic fonts. The same Qt code compiled on Windows can render the fonts in a correct way. So, for instance, the letter "a" is a note or a pause, or a clef...
In Mac, letter "a" remains an "a".
The strange thing is that if I open the font in the Font Book, the font is rendered correctly. So I also tried to use it on OpenOffice, Pages or TextEdit. Always on Mac symbolic fonts are rendered normally, typed letters remain letters.
Do you have any suggestions??
Thanks...
OK, one answer I found is to check the entire font map and grab the unicode value of the range of interest. For example, for the font I'm using is 0xf021-0xf0fb, so, you can draw a non text symbol like this:
char c = 0xf021;
QString str = QString( QChar( c ) );
painter.drawText( 10, 10, str );
I'm doing color transformations on glyphs rendered with CTFontDrawGlyphs, but I do not want to do those transformations to the emoji glyphs, since they have already a meaningful color information.
So, when I have a CTRun of glyphs, can I detect if it is actually emoji/color font?
I can do a string compare to the postscript name with "AppleColorEmoji", but seems awfully wasteful to do all the time, and somewhat hacky if there ever happens to be another font with the same features.
Ah, I can get the symbolic traits with CTFontGetSymbolicTraits, and check for kCTFontTraitColorGlyphs (or kCTFontColorGlyphsTrait), which, while undocumented, is available in the public headers.
I need to draw a column of vertical text (in Japanese language - it is drawn top-to-bottom instead of left-to-right) in my native C++ Win32 GUI application. I've looked through MSDN and only found how to draw right-to-left text.
How do I output top-to-bottom text except drawing each character separately?
The straight Win32 API has no way to draw (unrotated) vertical text (with an arbitrary font) in that way except 1 character at at time.
You can do more complex text output with GDI+
But that probably isn't what you want either, since the text will be vertical, but the characters will also be rotated.
Similarly, you can use CreateFont with an lfEscapement value of 900 or 2700 to get rotated text, but this will rotate everything. So that doesn't help either.
To do Japanese Top to Bottom drawing, you want the characters to be unrotated, but the placment of each character to advance in Y but not in X. Windows has no API that does this for all fonts. (you can do right-to-left and left-to-right, but not top-to-bottom).
In theory creating a font with an Orientation of 900 and an escapement of 2700 would do what you want, but it appears that if you set the escapement, then the orientation is ignored for most fonts. It's possible that for Japanese fonts, this will work differently. It's worth spending some time to play with. (see the addendum for more information on this)
I think your best bet is a probably a loop drawing one character at a time with ExtTextOut which gives you full control over the placement of each character.
If you use ETO_OPAQUE to draw the first character in a column, and not with all of the others, then you will be permitted to kern the characters vertically if you need to.
Addendum
Roygbiv points to an interesting article that says that fonts whose names begin with an # behave differently then other fonts when you use CreateFont a font with an lfEscapement value of 2700, These special fonts produce upright characters while still advancing down the page. So while there is no way to do what you want for arbitrary fonts, you may be able to get it working using certain fonts.
Options for Displaying Text
Out of curiosity, i wrote a small console app to enum fonts and list the names. My Windows Server 2003 machine has not fonts with names beginning with #. But my Windows 7 machine has a few. All seem to be Chinese fonts though, I see no Japanese fonts in the default Windows 7 Ultimate install.
The correct answer is:
There are three methods to do this:
Using the Edit or RichEdit controls to render your text
Using the Uniscribe API
Using the TextOut function with a font face name that begins with an at sign (#).
Here is an article that discusses some of these approaches.
Fortunately, with Win32 you do not need to write code to rotate characters. To display text vertically on Windows 2000 and Windows XP, enumerate the available fonts as usual, and select a font whose font face name begins with the at sign (#). Then create a LOGFONT structure, setting both the escapement and the orientation to 270 degrees. Calls to TextOut are the same as for horizontal text.
In Win32, use the lfEscapement member of a LOGFONT structure to define the rotation of a font:
LOGFONT LogFont
LogFont.lfEscapement = 900; // 90 degreees rotated text
... // Many more initializations
HFONT newFont = CreateFontIndirect(LogFont);
SelectObject(hdc, newFont);
char tx[255];
strcpy(tx, "vertical text");
TextOut(hdc, x, y, tx, strlen(tx)); // draw a vertical font
For More Information see the online Help of LOGFONT structure and of the CreateFontIndirect Function
HFONT gui_font = CreateFont( -MulDiv( 9, GetDeviceCaps( GetDC( hWnd ), LOGPIXELSY ), 72 ),
0,
900, // here
0,
FW_THIN, 0, 0, 0,
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY, FF_MODERN | FIXED_PITCH,
L"Segoe UI" );
Using lfEscapement (and if necessary lfOrientation) is superior in many ways to making the rectangle minimally wide (for instance: the dutch word 'wij' would have the 'i' and 'j' next to each other, because their combined width is less than the 'w'), or inserting a newline after each character.
The method this library uses sounds slow, but if do want it, it appears source code is provided:
http://www.ucancode.net/faq/CDC-DrawText-Drawing-Vertical-Text.htm
You may also find this discussion useful - http://www.eggheadcafe.com/forumarchives/win32programmergdi/Aug2005/post23542233.asp - apparently you need a vertical font (one beginning with #) and the API will take care of the rest.
As a quick hack type of answer, what happens if you use a standard control (CEdit for instance) and insert a new-line after every character typed?
Just an idea:
Did you try using DrawText or DrawTextEx using a very narrow rectangle that just fits the widest character?