【问题标题】:Matlab in Linux (Ubuntu 11.10) doesn't display Unicode (Hebrew) in plot figureLinux(Ubuntu 11.10)中的 Matlab 在图中不显示 Unicode(希伯来语)
【发布时间】:2012-03-21 07:09:17
【问题描述】:

我尝试在我的 Ubuntu 上的 Matlab 图形图中使用希伯来字符,但无济于事。我试过了:

text(0.6,0.5,'ירוק','fontname','times new roman','rotation',180,'fontsize',50,'color','r')

title('ירוק','fontname','times new roman','fontsize',50,'color','r')

类似于the answer to this question 中的建议。我收到了乱码(请参阅attached image)。

Matlab 的版本为 R2009b。当然我设置为 UTF-8 编码。

>> slCharacterEncoding

ans =

UTF-8

我还可以通过 ssh 访问远程计算机,版本为 R2011a。那也没有用。 (那里我不得不slCharacterEncoding('UTF-8')

另一个选项,使用javax.swing.JLabel 组件,对于我拥有的大量图形来说太难使用了。

我可以继续制作带有英文坐标轴和标题的图表,但很遗憾。有什么建议吗?


编辑:按照 Egon 的建议,如果我可以 print -deps 然后替换生成的 EPS 文件中的文本(来自 Matlab 中的代码),那也很酷。但我不知道如何将 Unicode 放在 EPS 中,我认为这是在拉伸它......


又一次修改:我开始认为这是一个 X 服务器问题。虽然不同,但如果这些问题相关,我不会感到惊讶:

我尝试卸载 Ubuntu 提供的 NVidia 驱动程序(我有一个 9300GS 卡)并重新安装 NVidia 提供的驱动程序 (v295)。我尝试将 xorg.conf 中的 DPI 更改为 "100 x 100"。安装了HebrewLocalizationHowto 中列出的所有软件包,然后安装了一些。没有任何效果。有什么建议吗?


另一个编辑 位于matlab/sys/fonts/ttfmatlab/sys/fonts/type1 下的字体未正确呈现。当我编辑图形并双击标题时,我看到字符在那里,但是当我完成编辑时,它返回到错误的渲染。此外,JLabel solution for rendering Unicode characters suggested here 在同一图形下正确呈现文本。

另一个编辑 Matlab R2011a 出现同样的问题。这是listfonts的输出

>> listfonts

ans = 

    'aharoni'
    'andale mono'
    'anka clm'
    'arial'
    'arial black'
    'avant garde gothic'
    'AvantGarde'
    'batang'
    'bitstream charter'
    'biwidth'
    'Bookman'
    'caladings'
    'century schoolbook l'
    'charter'
    'clean'
    'clearlyu'
    'clearlyu alternate glyphs'
    'clearlyu arabic'
    'clearlyu arabic extra'
    'clearlyu devanagari'
    'clearlyu devangari extra'
    'clearlyu ligature'
    'clearlyu pua'
    'cmex10'
    'cmmi10'
    'cmr10'
    'cmsy10'
    'comic sans ms'
    'comix no2 clm'
    'Courier'
    'courier 10 pitch'
    'courier new'
    'dingbats'
    'dorian clm'
    'dotum'
    'drugulin'
    'ellinia'
    'fangsong ti'
    'fixed'
    'frank ruehl'
    'gan clm'
    'georgia'
    'gladia clm'
    'gothic'
    'Helvetica'
    'Helvetica-Narrow'
    'impact'
    'itc avant garde gothic'
    'itc bookman'
    'itc zapf chancery'
    'itc zapf dingbats'
    'ktav yad clm'
    'latin modern roman'
    'latin modern sans'
    'latin modern sansquotation'
    'latin modern typewriter'
    'latin modern typewriter variable width'
    'lucida'
    'lucida bright'
    'lucidabright'
    'lucidasans'
    'lucidasans typewriter'
    'lucidatypewriter'
    'mincho'
    'msam10'
    'msbm10'
    'nachlieli'
    'new century schoolbook'
    'newcenturyschlbk'
    'NewCenturySchoolBook'
    'newspaper'
    'nil'
    'nimbus mono l'
    'nimbus roman no9 l'
    'nimbus sans l'
    'open look cursor'
    'open look glyph'
    'ozrad clm'
    'Palatino'
    'song ti'
    'standard symbols l'
    'Symbol'
    'terminal'
    'texgyreadventor'
    'texgyrebonum'
    'texgyrecursor'
    'texgyreheros'
    'texgyrepagella'
    'texgyreschola'
    'texgyretermes'
    'Times'
    'times new roman'
    'trebuchet ms'
    'urw bookman l'
    'urw chancery l'
    'urw gothic l'
    'urw palladio l'
    'verdana'
    'wasy10'
    'webdings'
    'yehuda'
    'zapf chancery'
    'zapf dingbats'
    'ZapfChancery'
    'ZapfDingbats'

【问题讨论】:

  • 你在开玩笑吗?我在我的引用了那个问题......
  • 你试过其他字体吗?您的 Times New Roman 副本可能不包含这些字符或不在正确的代码点处。 (无论如何,除了是一种相对难看的字体,恕我直言。)从您的列表中,我会以'yehuda' 开头,因为这听起来好像应该包含希伯来字母。

标签: matlab unicode plot hebrew figure


【解决方案1】:

您是否尝试过禁用文本解释器?

因此,要么添加'interpreter', 'none' 作为您对text 的调用的最后几个参数,要么将其设置为整个图形set(gcf,'defaulttextinterpreter','none')。 要在全局范围内应用它,只需将 gcf 替换为 0(即根窗口)。

如果这不起作用,您可以尝试使用 LateX 解释器(将 none 替换为上面的“latex”),它可能支持希伯来字符。

另一方面,但这是个人喜好,英文标签允许(几乎)任何人阅读您的数字,这仅允许您与其他人交流想法。

编辑 正如您引用的问题中所说,这是字体问题,而不是 MATLAB 问题。 我在我的 Arch 安装中尝试了它(它有它自己的字体问题),但我可以让它使用 Arial 字体很好地显示你的希伯来字符。

编辑 2 同样,这是字体问题,而不是 MATLAB。我在我的 Arch 安装上再次尝试了这个,现在希伯来语可以在你的第一个代码中正常工作。所以我假设你安装的字体不是正确的版本。

在 Arch 上,我安装了这些字体相关的软件包:

extra/cantarell-fonts 0.0.7-1
extra/font-bitstream-speedo 1.0.1-2
extra/fontsproto 2.1.2-1
extra/gsfonts 1.0.7pre44-3
extra/sdl_ttf 2.0.11-2
extra/t1lib 5.1.2-3
extra/ttf-bitstream-vera 1.10-8
extra/ttf-dejavu 2.33-2
extra/ttf-freefont 20100919-2
extra/xorg-font-util 1.3.0-1
extra/xorg-fonts-100dpi 1.0.1-4
extra/xorg-fonts-75dpi 1.0.1-4
extra/xorg-fonts-alias 1.0.2-2
extra/xorg-fonts-encodings 1.0.4-3
extra/xorg-fonts-misc 1.0.1-2
extra/xorg-fonts-type1 7.4-2
extra/xorg-mkfontscale 1.1.0-1
extra/xorg-xfontsel 1.0.4-1
extra/xorg-xlsfonts 1.0.3-2
community/ttf-liberation 1.07.2-1
aur/ttf-microsoft-wingding 1.55-1
aur/ttf-ms-fonts 2.0-9

对于 Ubuntu,我不记得正确的软件包,但我猜你使用 ttf-liberationttf-ms-conts(在 Ubuntu 中为 msttcorefonts)、xorg-fonts-100dpixorg-fonts-alias 的成功机会最高或他们的 Debian/Ubuntu 同行。

所以我认为有两种可能的解决方案:要么尝试另一种字体。 Arial 以前为我工作,T​​imes New Roman 现在也为我工作。或者在您的计算机上安装正确的字体。

编辑 在这方面,似乎 MATLAB 中的渲染工作几乎完美。但是,导出为 PDF 不起作用。任何位图格式都应该可以正常工作。

我的下一个猜测是,对于 PDF 案例,MATLAB 确实是罪魁祸首。我通过使用常规的 PDF 保存并打印到文件进行了一些测试。两者都表现出同样的问题。这并不奇怪,因为 MATLAB 中的 PDF 保存功能似乎会生成 PS,然后将其转换为 PDF。大概是 PS 一代发生了一些 rotten 和 unicode 不兼容的事情。

我知道这不是你问题的完整解决方案,但你至少可以将你的数字导出为 PNG,如果你的分辨率足够高,大多数人不会注意到。

如果您使用 LaTeX 生成报告,另一种解决方案是使用 matlab2tikz 生成您的数字,在那里我能够将希伯来文文本插入到 LaTeX 代码中。但是,由于我在我的 TeX 文件中没有使用希伯来语的经验,所以我不知道编译它的技巧。

【讨论】:

  • 英语很好,但我正在写一份用希伯来语写的实验室报告,因此更喜欢。我考虑过 TeX 和“无”解释器,所以我之前已经尝试过了。尝试 LaTeX 是一个好主意,但我不能输入非英文字符,否则会抱怨“警告:无法解释 TeX 字符串”并且无法显示。
  • @Yuval:我确实理解这两种方式都是个人偏好。使用 LaTeX,您可能需要以某种方式对您的希伯来语字符进行编码,但我对此没有任何经验,因为我自己无法读/写希伯来语。您的报告的替代方案可能是将数字导出为支持希伯来语的格式(只是猜测:EMF/WMF、PowerPoint、TikZ)?
  • 我不认为是字体问题;我也安装了大部分字体(xfonts-basexfonts-intl-europeanxfonts-100dpi-transcodedxfonts-efont-unicodexfonts-mathmlxfonts-75dpixfonts-efont-unicode-ibxfonts-scalablexfonts-75dpi-transcoded、@987653 xfonts-utils)。当我指定我已安装的 TTF 字体 (FreeSans) 时,它会变得很糟糕。否则,当我指定它时,它会很好地呈现Times New Roman,但它会在字符上产生混乱,这是不支持 UTF-8 的应用程序的典型特征。我相信这是一个 X-server 问题。
  • @Yuval,确实如此,所以它现在似乎也在我的电脑上。 MATLAB 渲染良好,但导出的 PDF 显示与您的图片类似的问题。您在 MATLAB 中的 listfonts 命令显示了多少种字体(大约 10 种?)。对于 Ubuntu,我从来没有遇到过任何问题,但在 Arch 上,我知道我必须更改一些东西才能获得完整的列表。
  • 已将listfonts 输出添加到问题中。
【解决方案2】:

使用下面的 sn-p 可以看到哪些字体很容易工作

x=listfonts
for i=1:numel(x) 
    display(x{i})
    title('ירוק','Color','red','FontName',x{i},'FontSize',50)
    pause
end

对我来说 Lucida Sans 工作。但是它会显示希伯来语反转。

您可以导出到 EPS(print -deps——我发现这在 Windows 中不可用;再说一次,您在那里没有问题)并进行一些修改:

  • 从 Matlab 中删除编码恐惧:简单删除所有出现的 \327
  • 添加 /Encoding 部分以将希伯来字符映射到 Matlab 输出的代码

也就是说,改变这个:

%%IncludeResource: font FreeSans
/FreeSans /ISOLatin1Encoding 200 FMSR

-6384  483 mt 
(\327\220\327\221\327\222\327\223\327\224\327\225\327\226\327\227\327\230\327\231\327\233\327\234\327\236\327\240\327\241\327\242\327\244\327\246\327\250\327\247\327\251\327\252\327\237\327\232\327\245\327\235\327\243) s

到这里:

/Encoding [
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/space /exclam /quotedbl /numbersign 
/dollar /percent /ampersand /quoteright 
/parenleft /parenright /asterisk /plus 
/comma /minus /period /slash 
/zero /one /two /three 
/four /five /six /seven 
/eight /nine /colon /semicolon 
/less /equal /greater /question 
/at /A /B /C 
/D /E /F /G 
/H /I /J /K 
/L /M /N /O 
/P /Q /R /S 
/T /U /V /W 
/X /Y /Z /bracketleft 
/backslash /bracketright /asciicircum /underscore 
/quoteleft /a /b /c 
/d /e /f /g 
/h /i /j /k 
/l /m /n /o 
/p /q /r /s 
/t /u /v /w 
/x /y /z /braceleft 
/bar /braceright /asciitilde /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/.notdef /.notdef /.notdef /.notdef 
/alefhebrew /bethebrew /gimelhebrew /dalethebrew 
/hehebrew /vavhebrew /zayinhebrew /hethebrew 
/tethebrew /yodhebrew /finalkafhebrew /kafhebrew /lamedhebrew 
/finalmemhebrew /memhebrew /finalnunhebrew /nunhebrew /samekhhebrew /ayinhebrew 
/finalpehebrew /pehebrew /finaltsadihebrew /tsadihebrew /qofhebrew /reshhebrew 
/shinhebrew /tavhebrew /.notdef /.notdef 
/.notdef /registered /macron 
/degree /plusminus /twosuperior /threesuperior 
/acute /mu /paragraph /periodcentered 
/cedilla /onesuperior /ordmasculine /guillemotright 
/onequarter /onehalf /threequarters /questiondown 
/Agrave /Aacute /Acircumflex /Atilde 
/Adieresis /Aring /AE /Ccedilla 
/Egrave /Eacute /Ecircumflex /Edieresis 
/Igrave /Iacute /Icircumflex /Idieresis 
/Eth /Ntilde /Ograve /Oacute 
/Ocircumflex /Otilde /Odieresis /multiply 
/Oslash /Ugrave /Uacute /Ucircumflex 
/Udieresis /Yacute /Thorn /germandbls 
/agrave /aacute /acircumflex /atilde 
/adieresis /aring /ae /ccedilla 
/egrave /eacute /ecircumflex /edieresis 
/igrave /iacute /icircumflex /idieresis 
/eth /ntilde /ograve /oacute 
/ocircumflex /otilde /odieresis /divide 
/oslash /ugrave /uacute /ucircumflex 
/udieresis /yacute /thorn /ydieresis 
] def

%%IncludeResource: font FreeSans
/FreeSans /Encoding 200 FMSR
1016  483 mt 
(\220\221\222\223\224\225\226\227\230\231\233\234\236\240\241\242\244\246\250\247\251\252\237\232\245\235\243) s

(编码部分可以按原样复制;\327 的出现已被删除)

这可行,但由于某种原因最后一个字符无法正确显示。这对我来说已经足够了。

【讨论】:

    猜你喜欢
    • 2012-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-07
    • 2012-02-03
    相关资源
    最近更新 更多