<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hello Радомир,</p>
<p>First I recommand this reading : <a
href="https://keithp.com/~keithp/talks/xtc2001/paper/">https://keithp.com/~keithp/talks/xtc2001/paper/</a></p>
<p>It is somehow out of date (particularly XftFont structure
description is false), but it permits to understand how Xft works.</p>
<p>In order to be sure to get a correct description of data
structures, look at the Xft, fontconfig and freetype header files.<br>
</p>
<p><b>First question</b> : if you want the upper left corner of your
text in "0,0" , you have to pass coordinates "0, font->ascent"
to XftDrawString function.</p>
<p>font is the XftFont structure associated with your font, and
ascent is the member of this structure corresponding to the
difference between the top of the higher character and its base
line.</p>
<p><b>Second question</b> : in order to determine how many pixels is
a white space for a given font, I calculate the difference between
the lengths of strings " e" and "e", the first string beginning
with a white space :</p>
<font size="+2"><tt>XGlyphInfo glyphInfo,gi1,gi2;</tt><tt><br>
</tt><tt>XftTextExtentsUtf8 (display,font,(FcChar8 *)("
e"),strlen(" e"),&gi1);</tt><tt><br>
</tt><tt>XftTextExtentsUtf8 (display,font,(FcChar8
*)("e"),strlen("e"),&gi2);</tt><tt><br>
</tt><tt>spaceWidth=gi1.width-gi2.width;</tt></font><br>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">But be aware that if the last character
of your string is a white space, it is not seen by
XftTextExtentsUtf8 function ; in this case, you have to test the
last character of your string, and if it's a white space, you have
to add the spaceWidth calculate upward to the length in pixels
calculated by XftTextExtentsUtf8.</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix"><b>Third question</b> : <br>
</div>
<div class="moz-cite-prefix">These are the members I use :</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix"><font size="+2"><tt>typedef struct
_XftFont {</tt><tt><br>
</tt><tt> int ascent; // see first question</tt><tt><br>
</tt><tt> int descent; // difference between bottom
and base line</tt><tt><br>
</tt><tt> int height;</tt><tt><br>
</tt><tt> int max_advance_width;</tt><tt><br>
</tt><tt> FcCharSet *charset;</tt><tt><br>
</tt><tt> FcPattern *pattern; // characteristics of the
font ; it is //
constructed from a patName string like <br>
</tt></font></div>
<div class="moz-cite-prefix"><font size="+2"><tt>
// "Liberation Sans-12:bold:roman" passed</tt></font></div>
<div class="moz-cite-prefix"><font size="+2"><tt>
// to FcNameParse function.</tt><tt><br>
</tt><tt>} XftFont;</tt></font></div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix"><b>Fourth question</b> : you have to
verify if anti-aliasing is enabled for your font like this :</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">fcResult=FcPatternGet(font,FC_ANTIALIAS
<style type="text/css">td p { background: transparent none repeat scroll 0% 0%; }p { margin-bottom: 0.25cm; line-height: 115%; background: transparent none repeat scroll 0% 0%; }a:link { color: rgb(0, 0, 128); text-decoration: underline; }</style>,0,
<style type="text/css">td p { background: transparent none repeat scroll 0% 0%; }p { margin-bottom: 0.25cm; line-height: 115%; background: transparent none repeat scroll 0% 0%; }a:link { color: rgb(0, 0, 128); text-decoration: underline; }</style>&fcValue);</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">if fcValue.u.i == 1 the anti-aliasing
is enabled</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">I think it is enabled by default ; what
is the name of your font ?</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">Le 28/11/2019 à 22:32, Радомир Хаџић a
écrit :<br>
</div>
<blockquote type="cite"
cite="mid:CAPV9uWvA6G1g0A8OyVLXkvyehf2No_Y-VA-6pTJMs82ChdPdrg@mail.gmail.com">
<pre class="moz-quote-pre" wrap="">I'm trying to implement word wrapping using Xlib and Xft. I have a few
questions and I hope some of you will answer at least some of them.
1. What to set the coordinates to in XftDrawString* functions? For
example, if I set them to (0,0), the top of the string is cropped.
2. By what amount to move the pen when we encounter a whitespace
(spaces, tabs, etc.) character? Currently, on every space I move the
cursor to the right by 5 pixels and on every tab four times that.
However the text looks uneven because of this:
A a B b C c D d
E e F f G g H h
I hope it's clear what I mean.
(I have to draw whitespace strings and non-whitespace strings
separately because I have to break if the word can't fit on the line.)
3. What do all the fields in XftFont structure represent?
4. For some reason the rendered text is "ugly". It is pixelated
instead of smooth for some reason, even though I know the font is
alright and it renders just fine in xterm. What can I do about this?
_______________________________________________
<a class="moz-txt-link-abbreviated" href="mailto:xorg@lists.x.org">xorg@lists.x.org</a>: X.Org support
Archives: <a class="moz-txt-link-freetext" href="http://lists.freedesktop.org/archives/xorg">http://lists.freedesktop.org/archives/xorg</a>
Info: <a class="moz-txt-link-freetext" href="https://lists.x.org/mailman/listinfo/xorg">https://lists.x.org/mailman/listinfo/xorg</a>
Your subscription address: %(user_address)s</pre>
</blockquote>
</body>
</html>