飞碟字体为unicode字符 [英] Flying Saucer font for unicode characters

查看:166
本文介绍了飞碟字体为unicode字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Grails导出插件生成PDF(基本上是Flying Saucer)。我的GSP页面是一个UTF-8页面(或者至少属性显示它是UTF-8,在GSP页面的开头,还有一个<?xml version =1.0编码=UTF-8?> 指令)。最初生成的PDF正确包含umlaut字符äöüõ,但是从西班牙语字符丢失了PDF(根本没有呈现)。然后我通过添加以下内容来更改我的css文件:

  @ font-face {
src :url(ARIALUNI.TTF);
-fs-pdf-font-embed:embed;
-fs-pdf-font-encoding:UTF-8;
}
body {
font-family:Arial Unicode MS,Arial,sans-serif;
}

ArialUni.ttf也部署到服务器。但是现在我正在收到两个变音字符和西里尔字符呈现为框。如果我正在将-fs-pdf-encoding属性值更改为Identity-H,那么变音符字符将被正确地渲染,但是西里尔字符被渲染为问号。



可以使用什么字体正确呈现变音符号和西里尔字符?或者可能是我的CSS有什么不对?任何提示都将不胜感激。



更新1:
我也尝试过以下css(由 http://fontface.codeandmore.com/ ):

  @ font-face {
font-family:'ArialUnicodeMS';
src:url('arialuni.ttf');
src:url('arialuni.eot?#iefix')格式('embedded-opentype'),
url('arialuni.woff')格式('woff'),
url ('arialuni.ttf')格式('truetype'),
url('arialuni.svg#arialuni')格式('svg');
font-weight:normal;
font-style:normal;
-fs-pdf-font-embed:embed;
-fs-pdf-font-encoding:UTF-8;
}

body {
font-family:'ArialUnicodeMS';
}

我添加了< meta http-equiv =Content-Typecontent =text / html; charset = UTF-8/>
我也试图用-Dfile.encoding = UTF-8运行grails,如下所述: http:// grails.1312388.n4.nabble.com/PDF-plugin-Having-problems-with-instalation-td2297840.html ,但没有任何帮助。没有显示西里尔字符。任何其他想法可能是什么问题?



* BTW: *我将PDF打包成zip,并将其发送回浏览器响应如下:

  response.setHeaderContent-disposition,attachment; filename = test.zip
response.setHeaderContent-Encoding,UTF-8
response.contentType ='application / zip'
response.outputStream<< zip
response.outputStream.flush()
response.outputStream.close()

我需要以某种方式考虑编码,同时加载????,我这样做:

  public static byte [ ] zipBytes(Map< String,ByteArrayOutputStream> fileNameToByteContentMap)throws IOException {
ByteArrayOutputStream zipBaos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(zipBaos);
fileNameToByteContentMap.eachWithIndex {String fileName,ByteArrayOutputStream baos,i - >
byte [] content = baos.buf
ZipEntry entry = new ZipEntry(fileName)
entry.setSize(content.length)
zos.putNextEntry(entry)
zos.write(content)
zos.closeEntry()
}
zos.close()
return zipBaos.toByteArray();
}


解决方案

由于某种原因,具有以下css和.ttf文件,它由face-kit生成器生成:

  @ font-face {
src:url('arialuni.ttf');
-fs-pdf-font-embed:embed;
-fs-pdf-font-encoding:Identity-H;
}

body {
font-family:Arial Unicode MS,Lucida Sans Unicode,Arial,verdana,arial,helvetica,sans-serif;
font-size:8.8pt;
}

奇怪的是,如果我把字体放入某个文件夹,让我们说字体,它会找到字体,但不会呈现字符。


I am generating PDF using Grails export plugin (basically, Flying Saucer). My GSP page is an UTF-8 page (or at least properties are showing that it is UTF-8, also in the beginning of the GSP page there is a <?xml version="1.0" encoding="UTF-8"?> directive). At first generated PDF properly contained umlaut characters "äöüõ", but Cyrillic characters were missing from PDF (not rendered at all). Then I've changed my css file as described in documentation by adding following:

@font-face {
    src: url(ARIALUNI.TTF);
    -fs-pdf-font-embed: embed;
    -fs-pdf-font-encoding: UTF-8;
}
body {
      font-family: "Arial Unicode MS", Arial, sans-serif;
}

ArialUni.ttf is also deployed to the server. But now I am getting both umlaut characters and Cyrillic characters rendered as boxes. If I am changing -fs-pdf-encoding property value to Identity-H then umlaut characters are rendered properly, but Cyrillic characters are rendered as question marks.

Any ideas of what font can be used to properly render both umlaut and Cyrillic characters? Or may be my CSS is somehow wrong? Any hints would be much appreciated.

Upd 1: I have also tried following css (which was generated by http://fontface.codeandmore.com/):

@font-face {
    font-family: 'ArialUnicodeMS';
    src: url('arialuni.ttf');
    src: url('arialuni.eot?#iefix') format('embedded-opentype'),
        url('arialuni.woff') format('woff'),
        url('arialuni.ttf') format('truetype'),
        url('arialuni.svg#arialuni') format('svg');
    font-weight: normal;
    font-style: normal;
    -fs-pdf-font-embed: embed;
    -fs-pdf-font-encoding: UTF-8;
}

body {
    font-family:'ArialUnicodeMS';
}

I've added <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> I was also trying to run grails with -Dfile.encoding=UTF-8, as was mentioned here: http://grails.1312388.n4.nabble.com/PDF-plugin-Having-problems-with-instalation-td2297840.html, but nothing helps. Cyrillic characters are not shown at all. Any other ideas what might be the problem?

*BTW:*I am packaging my PDF as zip and sending it back to browser in the response like that:

response.setHeader "Content-disposition", "attachment; filename=test.zip"
response.setHeader "Content-Encoding", "UTF-8"
response.contentType = 'application/zip'
response.outputStream << zip
response.outputStream.flush()
response.outputStream.close()

Do I need to somehow consider encoding while zipping????, which I do like that:

public static byte[] zipBytes(Map<String, ByteArrayOutputStream> fileNameToByteContentMap) throws IOException {
        ByteArrayOutputStream zipBaos = new ByteArrayOutputStream();
        ZipOutputStream zos = new ZipOutputStream(zipBaos);
        fileNameToByteContentMap.eachWithIndex {String fileName, ByteArrayOutputStream baos, i  ->
            byte[] content = baos.buf
            ZipEntry entry = new ZipEntry(fileName)
            entry.setSize(content.length)
            zos.putNextEntry(entry)
            zos.write(content)
            zos.closeEntry()
        }
        zos.close()
        return zipBaos.toByteArray();
    }

解决方案

For some reason it started working with following css and .ttf file, which was generated by face-kit-generator:

@font-face {
    src: url('arialuni.ttf');
    -fs-pdf-font-embed: embed;
    -fs-pdf-font-encoding: Identity-H;
}

body {
    font-family: Arial Unicode MS, Lucida Sans Unicode, Arial, verdana, arial, helvetica, sans-serif;
    font-size: 8.8pt;
}

Weird thing is that if I put font into some folder, let say "fonts", it will find the font but characters won't be rendered.

这篇关于飞碟字体为unicode字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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