- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我有一个 GtkEntry,我希望它允许用户使用他们选择的字体(或系统默认字体)来设置样式。我最终得到了一个 Pango 描述字符串,如“Monospace 10”来描述字体。
我目前正在使用 override_font
,它已被弃用以支持 CSS 样式。
我想至少尝试“正确”地做这件事,但现在从 Pango 字符串中获取 CSS 似乎是一个相当复杂和脆弱的工作流程。这是一个 example from Github :
def _get_editor_font_css():
"""Return CSS for custom editor font."""
font_desc = Pango.FontDescription("monospace")
if (gaupol.conf.editor.custom_font and
gaupol.conf.editor.use_custom_font):
font_desc = Pango.FontDescription(gaupol.conf.editor.custom_font)
# They broke theming again with GTK+ 3.22.
unit = "pt" if Gtk.check_version(3, 22, 0) is None else "px"
css = """
.gaupol-custom-font {{
font-family: {family},monospace;
font-size: {size}{unit};
font-weight: {weight};
}}""".format(
family=font_desc.get_family().split(",")[0],
size=int(round(font_desc.get_size() / Pango.SCALE)),
unit=unit,
weight=int(font_desc.get_weight()))
css = css.replace("font-size: 0{unit};".format(unit=unit), "")
css = css.replace("font-weight: 0;", "")
css = "\n".join(filter(lambda x: x.strip(), css.splitlines()))
return css
在 CSS 是一个字符串之后,然后我可以创建一个 CSSProvider
并将其传递给样式上下文的 add_provider()
(这是否最终会累积 CSS 提供程序,顺便问一下?)。
要将字体恢复到系统中似乎需要做很多工作,它可能会直接恢复到 Pango 中!
这真的是正确的做法吗?
最佳答案
使用PangoContext .
#include <gtkmm.h>
int main(int argc, char* argv[])
{
auto GtkApp = Gtk::Application::create();
Gtk::Window window;
Gtk::Label label;
label.set_label("asdasdfdfg dfgsdfg ");
auto context = label.get_pango_context();
auto fontDescription = context->get_font_description();
fontDescription.set_family("Monospace");
fontDescription.set_absolute_size(10*Pango::SCALE);
context->set_font_description(fontDescription);
Gtk::Label label2;
label2.set_label("xcv");
Gtk::VBox box;
box.pack_start(label);
box.pack_start(label2);
window.add(box);
window.show_all();
GtkApp->run(window);
return 0;
}
结果:
关于css - 从 Pango.FontDescription 设置 GtkEntry 字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41257101/
我正在使用 Pango 来排版梵文。考虑由梵文字母 U、梵文字母 MA、梵文符号 VIRAMA、梵文字母 KA、梵文字母 NA、梵文符号 VIRAMA、梵文字母 CHA、梵文元音符号 AU 组成的字符
我正在尝试在使用 pango 构建的绘图中标记 y 轴。 我无法将文本定向为沿 y 轴垂直向上。 代码的相关部分是: #include Pango::FontDescription font;
我有一个代码使用Cairo和 Pango创建图像: #include #include #include #define IMAGE_WIDTH 650 #define IMAGE_HEIGHT 1
我有一个使用 pango 的文本框实现。如果我在从右到左的脚本中放置一个以单词开头的字符串,后跟一个空格,然后在从左到右的脚本中放置单词,则 pango 使用的自动换行会变得困惑(使用 PANGO_W
我想要一个左对齐标签,其中包含一些粗体文本,但使用以下代码(不返回错误)未设置对齐方式...有人知道吗? (python2.7、gtk2.24) label=gtk.Label(""+text+"")
我正在尝试将标签添加到 GTK3 窗口,然后设置标签的字体大小。这是我的尝试: #include static void add_label (GtkWidget* window, gchar *t
第一次海报; Stack Overflow 天使的长期崇拜者。 我在 Pango 控制的跨度文本中遇到颜色问题。 长版: 我正在更新一个旧的 UI 程序,它具有带有 GTK、XML(由 Glade 编
我正在使用 pangomm 渲染一些文本,但我使用的字体没有部分文本的字形(在这种情况下,有一些日语和英语混合在一起)。 Pango 似乎使用后备字体正确呈现文本。 如何确定将哪种字体用作备用字体?
我正在使用 GTK Sharp 为我的应用开发一些 GUI。 看看这段代码: Pango.FontDescription fontdesc = new Pango.FontDescription();
我觉得我可能会错过 Pango 的一些东西。 API 中的几乎所有内容似乎都适合显示静态文本,除了在特定位置绘制/移动光标的两个函数除外,这表明可能有一种内置的方式来实现编辑文本。 例如,要用鼠标标记
我的程序有一个 gtk.TreeView,它显示一个 gtk.ListStore。 gtk.ListStore 包含这样的字符串: ""+site_title+""+"\n"+URL URL 显然是一
Cabal 在尝试安装 pango 时失败,提示它找不到 pkg-config。 peauters:~ $ sudo cabal install pango -v Password: Reading
我正在尝试在 ubuntu 上构建 gtk+1.3,但在配置过程中出现错误, ld: cannot find -lpango 我尝试安装大量 pango 库,但仍未安装,所以我不确定该怎么做。我一直在
根据 this documentation , Pango 能够处理一些便利标签,如 粗体,或 为斜体。 但是,没有什么可以换行的,比如常用的 .有没有办法让 Pango 能够处理换行? 最佳答案 通
启动使用Pango库的任何内容时出现此错误。我正在使用Kubuntu 9.10。我已经在libgtk * libcairo * libpango *和fontconfig上完成了'sudo apt-g
我正在构建 firefox 的定制源代码。当我要构建 firefox 时,出现以下错误,提示“没有 pango 包错误”。我该如何解决这个错误。 最佳答案 如果您使用的是 Ubuntu 18.04 或
我正在使用 librsvg 将 SVG 文件渲染到开罗上下文。之后,我使用 Pango “手动”在顶部渲染一些文本。 渲染 SVG 时,我收到 Pango 警告,指出它无法加载字体: “无法加载字体“
我正在构建 firefox 的定制源代码。当我要构建 firefox 时,出现以下错误,提示“没有 pango 包错误”。我该如何解决这个错误。 最佳答案 如果您使用的是 Ubuntu 18.04 或
我在让 Pango Cairo 自动换行时遇到问题。下面是一些演示代码。我将布局的宽度设置为与红色矩形相同,因此我希望它环绕到红色矩形。实际上,它只是在每一行上放置一个单词,就好像宽度设置得很小一样。
我需要 pyCairo 做的是: 生成一个大小为 100x100 的图像,其中包含一些文本和来自文件系统的图像作为背景 文本应位于文本环绕大小为 20x20 且左下角位于 (40,40) 的框中。 保
我是一名优秀的程序员,十分优秀!