Hello again Monks, i have a problem with TTFMetrics giving me a wrong values for unicode strings.
here's an example:
/the string doesn't show properly in the code section, so here it is "بلحة"/
use warnings;
use strict;
use Font::TTFMetrics;
use utf8;
my $metrics = Font::TTFMetrics->new("Arial.ttf"); #16px
my $str_en = ($metrics->string_width("Balha") * 1152) / (147456);
my $str_ar = ($metrics->string_width("بلحة")
+* 1152) / (147456);
my $str_ar2 = ($metrics->string_width("\x{0628}\x{0644}\x{062D}\x{062
+9}") * 1152) / (147456);
print ('My English string: ' . "$str_en" . "px\n");
print ('My Unicode string: ' . "$str_ar" . "px\n");
print ('My Unicode string 2: ' . "$str_ar2" . "px\n");
the output is:
My English string: 40.921875px
My Unicode string: 33.0390625px
My Unicode string 2: 33.0390625px
the width value of the english string is correct. and for the unicode string is wrong and should be 21 px.
is there something i should do to make it right?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.