在SVG for iOS Chrome和Safari中显示自定义字体

我使用的谷歌自定义字体的svg,但我自己托pipe。 这里是以下代码的SVG文件 :

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="430" height="590"> <defs> <style type="text/css"><![CDATA[ @font-face { font-family: 'Fjalla'; src: url('http://build-podcast.com/fonts/fjalla.eot'); src: url('http://build-podcast.com/fonts/fjalla.eot?#iefix') format('embedded-opentype'), url('http://build-podcast.com/fonts/fjalla.woff') format('woff'), url('http://build-podcast.com/fonts/fjalla.ttf') format('truetype'), url('http://build-podcast.com/fonts/fjalla.svg#fjalla') format('svg'); font-weight: normal; font-style: normal; } text { font-family: Fjalla, sans-serif; font-weight: bold; fill: #4b5568; } ]]> </style> </defs> <g id="logo"> <text x="135" y="60" font-size="210" transform="rotate(45)">/</text> <text x="115" y="363" font-size="210" transform="rotate(-45)">\</text> <text x="15" y="341" font-size="200">build</text> <text x="15" y="475" font-size="127">podcast</text> <text x="21" y="540" font-size="36">screencasts on tech tools</text> </g> </svg> 

我正在使用img标签在主网站上显示它

 <img src="logo.svg"> 

它在桌面浏览器上甚至在Android Chrome等移动浏览器上都能正常显示。 但是它在iOS 7 Chrome或Android中完全不显示。 任何线索我如何可以修改自定义字体部分的SVG文件代码? 谢谢!

我们最近有同样的问题在SVG图像中显示自定义字体。 在实施此修复之前,文本在某些设备上不会显示在iOS中。 经过大量的debugging和尝试不同的方式来解决这个问题,我们最终得到了一个CSS Font Fallback解决scheme。 这是我们解决同样问题的唯一方法。

以下是我们如何实现它:

首先,我们使用Adobe Illustrator来提取字符的形状,如下所示:

 <font horiz-adv-x="2048"> <font-face font-family="RobotoCondensed-Light" units-per-em="2048" underline-position="-150" underline-thickness="100"/> <missing-glyph horiz-adv-x="434"/> <glyph unicode=" " horiz-adv-x="434"/> <glyph unicode="&quot;" horiz-adv-x="549" d="M217,1341l-36,-261l-68,0l2,254l0,226l102,0M442,1341l-36,-261l-68,0l2,258l0,222l102,0z"/> <glyph unicode="," horiz-adv-x="346" d="M246,19l-100,-277l-77,0l56,280l0,168l121,0z"/> <glyph unicode="-" horiz-adv-x="497" d="M445,568l-399,0l0,104l399,0z"/> <glyph unicode="." horiz-adv-x="440" d="M276,0l-130,0l0,166l130,0z"/> <glyph unicode="0" horiz-adv-x="978" d="M867,564C867,376 834,232 767,131C700,30 607,-21 490,-21C372,-21 279,30 212,131C144,232 110,377 110,564l0,326C110,1077 144,1221 211,1324C278,1426 370,1477 488,1477C606,1477 699,1426 766,1324C833,1222 867,1077 867,890M747,911C747,1059 725,1173 681,1252C636,1331 572,1371 488,1371C405,1371 341,1331 297,1252C253,1172 231,1058 231,911l0,-366C231,398 253,285 298,204C343,123 407,83 490,83C573,83 637,123 681,204C725,284 747,398 747,545z"/> <!-- ...... Complete characterset ...... --> </font> 

然后我们使用CSS定义字体:

 <defs> <style type="text/css"> <![CDATA[ @font-face { font-family: 'RobotoCondensed-Light-Fallback'; font-style: normal; font-weight: 300; src: url(data:application/x-font-woff;charset=utf-8;base64,d09GRg............7yEuAS1Fmtsgn2C3mGC7pcSzGaItVzpDHKXKRoB2nd8b5m1ni67q0DVvtWpxe61sF59tcm+qiK+1YY21P2oWNdkPaA1Nv0meNl0KL0HwqtAmtRKFDaA9/APTVpT1K/YclSp7tiAGxtzbsEoOZYV9u9g8VM0kokz6M/klEI+HecECMVpoFhuIDsL5bmwAAAVSQKFMAAA==) format('woff'); } ]]> </style> </defs> 

一旦我们将字体命名为“RobotoCondensed-Light-Fallback”,然后:

 <text style="font-family:RobotoCondensed-Light,RobotoCondensed-Light-Fallback,Arial,sans-serif; font-weight: 300" font-size="36">Text</text> 

会发生什么情况是,iOS使用<font-face>而所有其他浏览器使用后备字体。

希望这可以帮助!

为了您的信息,我们在SVG中使用了这个定义。

 <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="270px" height="303px" viewBox="0 0 270 303" enable-background="new 0 0 270 303" preserveAspectRatio="xMidYMid meet" xml:space="preserve">