I had the same problem and not founding a proper way to do it, without creating intermediate images, just used inverted chars.
"use strict";
include(fb.ComponentPath + 'docs\\Flags.js');
String.prototype.flip = function() {
const last = this.length - 1;
let result = new Array(this.length)
for (let i = last; i >= 0; --i) {
let c = this.charAt(i);
let r = flipTable[c];
result[last - i] = r !== void(0) ? r : c;
}
return result.join('');
}
const flipTable = {
a : '\u0250',
b : 'q',
c : '\u0254',
d : 'p',
e : '\u01DD',
f : '\u025F',
g : '\u0183',
h : '\u0265',
i : '\u0131',
j : '\u027E',
k : '\u029E',
//l : '\u0283',
m : '\u026F',
n : 'u',
r : '\u0279',
t : '\u0287',
v : '\u028C',
w : '\u028D',
y : '\u028E',
'.' : '\u02D9',
'[' : ']',
'(' : ')',
'{' : '}',
'?' : '\u00BF',
'!' : '\u00A1',
"\'" : ',',
'<' : '>',
'_' : '\u203E',
';' : '\u061B',
'\u203F' : '\u2040',
'\u2045' : '\u2046',
'\u2234' : '\u2235',
'\r' : '\n'
}
for (let i in flipTable) {flipTable[flipTable[i]] = i}
const gFont = gdi.Font('Segoe UI', 10);
function on_paint(gr) {
const text = 'Hello'.flip();
gr.SetTextRenderingHint(TextRenderingHint.ClearTypeGridFit);
const w = gr.CalcTextWidth(text, gFont);
const h = gr.CalcTextHeight(text, gFont);
gr.GdiDrawText(text, gFont, 0x000000, (window.Width - w)/2, (window.Height - h)/2, window.Width, window.Height); // From top to bottom
gr.SetTextRenderingHint(TextRenderingHint.SystemDefault);
let x = (window.Width - w)/2;
let y = (window.Height - h)/2 + 20;
[...text].reverse().forEach((key, i) => {
const w = gr.CalcTextWidth(key, gFont);
gr.GdiDrawText(key, gFont, 0x000000, x, y, w, h, StringFormatFlags.DirectionVertical); // From top to bottom
x += w;
});
x = (window.Width - w)/2;
y += 20;
[...text].reverse().forEach((key, i) => {
const w = gr.CalcTextWidth(key, gFont);
gr.GdiDrawText(key, gFont, 0x000000, x, y, w, h, StringFormatFlags.DirectionVertical); // From top to bottom
y += h;
});
}
Play with chars and flags.
Have not found a way to align text to top, i.e. 'H' does not measure in height the same than 'o', but CalcTextHeight keeps giving the same result for both (so I can not reduce the vertical offset per letter).