linux,C ++,xft:怎么用呢? [英] linux, C++, xft : how to use it?

查看:195
本文介绍了linux,C ++,xft:怎么用呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Xft,教程,好让他们调用教程...看起来像是写在一个北韩的营地...我还发现这一个。所以让我尝试一步一步:

  // g ++ XftTest.cc -lX11 -lXft`pkg- config --cflags freetype2` 
#include< unistd.h>
#include< X11 / Xlib.h>
#include< X11 / Xutil.h>
#include< X11 / Xft / Xft.h>
int main()
{
显示*显示;
XftFont * font;
XftDraw * xftdraw;
XRenderColor xrcolor;
XftColor xftcolor;

display = XOpenDisplay(0);
Window XP = XCreateSimpleWindow(display,DefaultRootWindow(display),0,0,360,90,0,0,0);
XMapWindow(display,XP);

font = NULL; / * added 6/16 * /

// font = XftFontOpenName(display,0,NorthKorea-50); //如何检查这是否好?
font = XftFontOpenName(display,0,)/ * added 6/16 * /
if(!font)return 1;

xftdraw = XftDrawCreate(display,XP,DefaultVisual(display,0),DefaultColormap(display,0));

xrcolor.red = 65535;
xrcolor.green = 0;
xrcolor.blue = 0;
xrcolor.alpha = 65535;
XftColorAllocValue(display,DefaultVisual(display,0),DefaultColormap(display,0),& xrcolor,& xftcolor);

XftDrawString8(xftdraw,& xftcolor,font,20,70,(XftChar8 *)Joe Dalton,10);

XFlush(display);

sleep(2);

XftDrawDestroy(xftdraw);
XftColorFree(display,DefaultVisual(display,0),DefaultColormap(display,0),& xftcolor);

return 0;
}

,你可以在 XftFontOpenName
XftFontOpenName(display,0,NorthKorea-50)
如果你写一个胡说,是没有错误或东西告诉我,我没有一个字体叫NorthKorea。这是有意义的,因为 XftFontOpenName 从字符串返回最近的字体。



那么,我如何检查我的字体是否匹配?如何使用像arial这样的字体?我试过XftFontOpenName(显示,0,arial-50),我没有什么不同。



在我的系统,我有我的字体文件夹中的这些文件夹: p>

  $ ls / usr / share / fonts / 
100dpi 75dpi cyrillic编码misc OTF TTF Type1 util



我可以使用这些文件夹中的任何字体吗?



如果你们有一些很好的互联网链接,这将是一个高兴,我来看看。



n.b。 :没有xft标签...



更新6/16



...
我不明白,如果我替换

  font = XftFontOpenName(display,0, NorthKorea-50); 

  font = XftFontOpenName(display,0,); 

它仍然加载字体...



xlsfonts返回很多东西,像dat一样:

  -monotype-courier new-bold-r- 0-0-0-0-m-0-iso8859-10 

但将此作为参数传递 XftFontOpenName 更改什么;我尝试加载 XftFontOpenXlfd 的字体,它总是返回 NULL ...

解决方案

xft使用fontconfig进行字体发现。 xlsfonts是一种查询旧X core字体系统fontconfig的替代方法。 xlsfonts结果不会以任何可靠的方式映射到fontconfig状态。



因此:


  1. 忘记任何快捷方式,其中xft工作排序 - 像X核心字体系统记录在上个世纪的科技书籍。它是完全不同的。它不是X核心字体与抗锯齿和truetype支持。


  2. 阅读fontconfig文档,在你的fontconfig配置文件中,可以使用现代字体和抗锯齿,系统,并使用fontconfig实用程序(fc-query,fc-list等)查询fontconfig状态


  3. 字体和fontconfig)已经告诉你,不要 尝试直接使用xft。 xft是第一次尝试写入新字体堆栈的产物。它的功能不足以管理现代文本和现代字体。很久以前,处理现代字体格式复杂性的部分已经在pango中推出了(因为它证明是复杂的,它值得一个单独的项目)。如果你试图单独使用xft,你会迟早遇到pre-pango代码的缺陷,没有人会有兴趣修复你的问题,因为相同的代码已经经历了十年的修复pango端。避免pango不是一个捷径。避免pango试图依靠半完成,放弃多年的项目。


  4. 忘记匹配特定的字体文件。 fontconfig将积极打击以这种方式工作的任何尝试。在后核心字体世界中,你给字体系统一个字体模式,它会为你构建一个匹配的字体。如果结果不是你期望的字体文件,因为文件被评估,并发现缺乏。如果你希望fontconfig使用这个文件,你必须修复字体文件(添加丢失的字形,缺少的字体样式等),而不是写代码试图强制它。 Fontconfig认为渲染用户可以阅读的文本比仅渲染宠物字体可以做的部分更重要。是的,现在是你如何习惯在其他系统上思考它。 fontconfig是不同的。没有什么短的重写将使它的行为像你所期望的。没有人对这种重写感兴趣,因为在过去的几年中,fontconfig已经相当成功。


字体 opentype text-rendering fontconfig linux


I try to use Xft, the tutorial, well let them calling that a tutorial... looks like it was written in a north korean camp... I also found this one. So let me try to do a step-by-step :

// g++ XftTest.cc -lX11 -lXft `pkg-config --cflags freetype2`
#include<unistd.h>
#include<X11/Xlib.h>
#include<X11/Xutil.h>
#include<X11/Xft/Xft.h>
int main()
{
  Display *display;
  XftFont      *font;
  XftDraw      *xftdraw;
  XRenderColor xrcolor;
  XftColor     xftcolor;

  display = XOpenDisplay(0);
  Window XP = XCreateSimpleWindow(display,DefaultRootWindow(display),0,0,360,90,0,0,0);
  XMapWindow(display,XP);

  font = NULL; /* added 6/16 */

  //font = XftFontOpenName(display,0,"NorthKorea-50"); // how to check if this is good ?
  font = XftFontOpenName(display,0,"") /* added 6/16 */
  if (!font) return 1;

  xftdraw = XftDrawCreate(display,XP,DefaultVisual(display,0),DefaultColormap(display,0));

  xrcolor.red  =65535;
  xrcolor.green=0;
  xrcolor.blue =0;
  xrcolor.alpha=65535;
  XftColorAllocValue(display,DefaultVisual(display,0),DefaultColormap(display,0),&xrcolor,&xftcolor);

  XftDrawString8(xftdraw, &xftcolor, font, 20,70 , (XftChar8 *)"Joe Dalton", 10);

  XFlush(display);

  sleep(2);

  XftDrawDestroy(xftdraw);
  XftColorFree(display,DefaultVisual(display,0),DefaultColormap(display,0),&xftcolor);

  return 0;
}

as you can see, in the XftFontOpenName : XftFontOpenName(display,0,"NorthKorea-50") if you write a bullshit, like I did, there is no error or something to tell me that I don't have a font called NorthKorea. That make sense since XftFontOpenName returns the nearest font from the string.

So, how can I check if my font match or not ? how can I use a font like arial? I tried XftFontOpenName(display,0,"arial-50"), I got nothing different.

On my system, I have these folders in my fonts folder :

$ls /usr/share/fonts/
100dpi  75dpi  cyrillic  encodings  misc  OTF  TTF  Type1  util

can I use any font in these folders by the same way ?

if you guys have some nice internet links, it would be a pleasure for me to take a look.

n.b. : there is no xft tag...

update 6/16

I'm still stuck with dat stuff... I don't understand, if I replace

font = XftFontOpenName(display,0,"NorthKorea-50");

by

font = XftFontOpenName(display,0,"");

it still loading a font...

xlsfonts return a lot of stuff, like dat one :

-monotype-courier new-bold-r-normal--0-0-0-0-m-0-iso8859-10

but passing this as argument to XftFontOpenName changes nothing; I try to load a font with XftFontOpenXlfd too, it returns always NULL...

解决方案

xft uses fontconfig for font discovery. xlsfonts is a way to query the old X core fonts system fontconfig replaced. xlsfonts results won't map in any reliable way way to the fontconfig state.

So:

  1. forget about any shortcut where xft work sort-of like the X core font system documented in last centuries tech books. It is completely different. It is not X core fonts with antialiasing and truetype support. It is something that can use modern fonts and do antialiasing, but definitely not X core fonts in any form

  2. Read the fontconfig documentation, the fontconfig configuration files on your system, and use fontconfig utilities (fc-query, fc-list, etc) to query the fontconfig state

  3. as the people who maintain xorg (both x core fonts and fontconfig) already told you, do not try to use xft directly. xft is the product of the first attempt to write a new font stack. Its capabilities are not sufficient to manage modern text and modern fonts. The part dealing with modern font format complexities has been spun out in pango a long time ago (because it was proving complex enough it deserved a separate project). If you try to use xft alone, you'll hit the deficiencies in pre-pango code sooner or later, and no one will be interested in fixing your problems because the same code has already been subjected to a decade of fixes pango-side. Avoiding pango is not a shortcut. Avoiding pango is trying to rely of an half-finished, abandonned for years project.

  4. forget about matching a specific font file. fontconfig will actively fight any attempt to work this way. In the post-core-fonts world, you give the font system a font pattern, and it will build a matching font for you. If the result is not the font file you expected that's because the file was evaluated and found lacking. If you want fontconfig to use this file you will have to fix the font file (add the missing glyphs, the missing font styles, etc), not write code to try to force it anyway. Fontconfig considers that it's more important to render a text your users can read, than to only render the parts your pet font can do. And yes that's now how you're used to think about it on other systems. fontconfig is different. Nothing short of a rewrite will make it behave like you expect. No one is interested in this rewrite because by and large fontconfig has been quite successful those past years.

这篇关于linux,C ++,xft:怎么用呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆