在cairo_pdf中设置粗体样式 [英] Set bold style in cairo_pdf

查看:74
本文介绍了在cairo_pdf中设置粗体样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 cairo_pdf()在R中生成带有漂亮字体的绘图.如果我指定的字体系列具有合理的基本粗细命名,例如"Arial"包含Arial Regular,Arial Bold,Arial Italic和Arial Bold Italic.

I'm using cairo_pdf() to generate a plot in R with nice fonts. It works fine if the font family I specify has basic weights named sensibly, e.g. "Arial" contains Arial Regular, Arial Bold, Arial Italic, Arial Bold Italic.

但是有没有一种方法可以随意设置给定样式的字体?例如,在Hoefler文字中,我有Hoefler文字 Black 而不是粗体.我可以得到cairo_pdf将此重量用于粗体文本吗?

But is there a way to arbitrarily set the font for a given style? For example, in Hoefler Text I have Hoefler Text Black not Bold. Can I get cairo_pdf to use this weight for bold text?

推荐答案

我可能使用的操作系统与您不同,但我想知道是否有可能在Linux机器上成功完成此任务,尽管这样做可能不会成功在我的Mac上成功.字体样式是由Mac专用的应用程序FontBook.app确定的,但我想您具有 fontforge 或类似的访问方式,可以确定所需的样式名称.:

I'm probably using a different OS than you but I'm wondering if there's a chance that this will succeed on a Linux box, although it doesn't succeed on my Mac. The font styles were determined with Mac-specific application, FontBook.app, but I imagine that you have fontforge or similar access to a way to determine needed names of styles.:

 Cairo::CairoFonts(    # for some reason I seem to need the `pkgname::` format
    regular="Hoefler Text:style=Regular",
    bold="Hoefler Text:style=Black",
    italic="Hoefler Text:style=Italic",
    bolditalic="Hoefler Text:style=Black Italic",
    symbol="Symbol"
 )
Cairo::CairoFontMatch("Hoefler Text:style=Black",verbose=TRUE)
cairo_pdf("test_bold.pdf", family="Hoefler Text") 
     plot(1,1, main=bquote(bold(test~fl~ligature)) )
dev.off()

我的机器上的输出似乎是在'Hoefler Text'系列中,但是样式似乎与非粗体调用没有什么不同.我认为Linux机器可能会更好.

The output on my machine appears to be in the 'Hoefler Text' family, but the style does not appear to be any different that the non-bold call. I thinking a Linux machine might have better luck.

更新:我使用在SO搜索中找到的在线字体转换器"之一将"Hoefler Text.ttc"(TrueType集合)字体提取到其组件中.我将它们移到/Library/Fonts/目录中.我查看了 Cairo :: CairoFontMatch("HoeflerText:style = Black",verbose = TRUE)的输出,并看到那里正在看到ttc文件,因此我将原始ttc文件移到了-字体目录并重新启动R.现在,当我运行时:

Update: I used one of the "online font converters" found on an SO search to extract the 'Hoefler Text.ttc' (a TrueType collection) fonts into its components. I moved them into the /Library/Fonts/ directory. I looked at the output from Cairo::CairoFontMatch("HoeflerText:style=Black",verbose=TRUE) and saw that there it was seeing the ttc file so I moved the original ttc file to a non-Font directory and restarted R. Now when I run:

cairo_pdf("test_bold.pdf", family="HoeflerText")
  plot(1,1, main=bquote(bold(test~fl~ligature)) ); dev.off() 

...,然后在我的PDF查看器中查看,我看到一个粗体字体作为标题.我不确定这是否是a)用R重新映射字体的结果,或者b)查看器现在正在正确查找并且cairo_pdf设备没有给它正确的名称,所以我不确定.无论如何,我现在可以进行正确的查找:

... and view in my PDF viewer I see a bold font as title. I am not sure if this is actually a result of a) remapping the fonts by R or if b) the viewer is now doing the proper lookup and had not been given the correct name by the cairo_pdf device. At any rate, I am now able to do the correct lookup:

> Cairo::CairoFontMatch("HoeflerText:style=Black",verbose=TRUE)
1. family: "Hoefler Text", style: "Black", file: "/Library/Fonts/HoeflerText-Black.ttf"
   "Hoefler Text-12:familylang=en:style=Black,黑體,Sort,Sehr fett,Lihava,Noir,Nero,ブラック,두껍게,Zwart,Svart,Preto,Насыщенный жирный,Extrafet,黑体,Negra:stylelang=en,zh-tw,da,de,fi,fr,it,ja,ko,nl,no,pt,ru,sv,zh-cn,es:fullname=Hoefler Text Black:fullnamelang=en:slant=0:weight=0:width=100:pixelsize=12.5:foundry=unknown:hintstyle=3:hinting=True:verticallayout=False:autohint=False:globaladvance=True:file=/Library/Fonts/HoeflerText-Black.ttf:index=0:outline=True:scalable=True:dpi=75:scale=1:charset=  |>^1!|>^1!P0oWQ U>w0A|>^1!|>^1!!!!%#lm6Uq{tu}/lr9j#{}!CB!!OoV!/9m> !%J<G!!!)$&olY4 !^^7$   9;*f! !!!.%!!#&|!!!&S    !!!!# !!!1&|>^1!|>^1!|>^1!!)Ib~9R6#i(){NjxJemz#%jg%!!#0GM>RAd#y#fx!!!!5s<..R!!%U3!!![t  !!#3H !!!!n      !!#6I;sG44!!!?+!!!%#!!!!X    !!#AL      !!!1& !!+lx       P0oWR!!+u{!!!#/       !!+~~  !9PX<!!!!#    :lang=aa|av|ay|az-az|ba|be|bg|bi|br|bs|bua|ca|ce|ch|chm|co|cs|cv|da|de|en|es|et|eu|fi|fj|fo|fr|fur|fy|gd|gl|gv|ho|hr|hu|ia|id|ie|ik|io|is|it|kaa|kk|kum|kv|ky|lb|lez|lt|lv|mg|mh|mk|mo|mt|nb|nds|nl|nn|no|nr|nso|oc|om|os|pl|pt|rm|ro|ru|sel|sh|sk|sl|sma|smj|so|sq|sr|ss|st|sv|sw|tg|tk|tl|tn|tr|ts|tt|tyv|uk|uz|vo|vot|wa|wen|xh|yap|zu|an|crh|csb|fil|hsb|ht|jv|kj|ku-tr|kwm|li|mn-mn|ms|ng|pap-an|pap-aw|rn|rw|sc|sg|sn|su|za:fontversion=65536:capability=otlayout\:DFLT otlayout\:cyrl otlayout\:grek otlayout\:latn:fontformat=TrueType:embeddedbitmap=True:decorative=False:namelang=en:prgname=R:hash=sha256\:6ad00ff0335de002e10e0dc0aca8b6282ba3425c3b2f8ce3f0a6fea668d0a711:postscriptname=HoeflerText-Black"

这篇关于在cairo_pdf中设置粗体样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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