我需要在X11应用程序的X11窗口中对齐文本。 对齐必须取决于窗口大小,字体大小和字符串长度。 在此先感谢:)
我想在x11窗口中使用单元格填充的概念。我正在使用xft字体文本。我使用上升,下降来垂直对齐它。现在我想帮助将它水平对齐(左,中,右和对齐),就像在MSWord中一样。
Example for horizontal+vertical spacing
我想,现在每个人都能理解我的需要。
I need the text with cell padding
`XftTextExtents8(display, fontXft, (XftChar8 *)textStr, strlen(textStr),&extents);
fontWidth = extents.width -extents.x;
singleFontHeight = fontXft->ascent - fontXft->descent;
if(vAlign == TOP_ALIGN)
textY = singleFontHeight;
else if(vAlign == CENTER_ALIGN)
textY = ((heightWin - fontHeight)/2 + singleFontHeight);
else
textY = heightWin;
if(hAlign == CENTER_ALIGN)
textX = (widthWin - fontWidth)/3;
else if(hAlign == RIGHT_ALIGN)
textX = widthWin - fontWidth;
else
textX = 0;`
答案 0 :(得分:0)
我可以看到您的代码中至少有一个错误,那就是当字形的高度实际上都是正数时,您将字形的高度视为(上升-下降),因此总高度应为(上升+下降)。
我也看不出为什么要使用中心对齐(窗口宽度-字符串宽度)/ 3,除非您想要在右侧填充一些内容。