矢量图和Word:EPS,PDF,EMF和SVG

1.EMF和Word

  在学校的时候,我思考过一个问题,论文中的插图如何保证清晰度。关键之一就是使用矢量图。参考知乎问题:如何在论文中画出漂亮的插图?。常见的矢量图包括:EPS,EMF和SVG。SVG适合于浏览器,EPS适合于LaTeX,EMF才适合Word。所以,如果在Word插图,最好是使用EMF格式。常见的软件如Origin Pro,Mathematica , GNUPlot , Matlab以及R均可以将图形导出为EMF。其中MATLAB在新版之前,导出的图形质量一直不太好。而Origin Pro的图形质量应该是最好的。

  下面的程序演示了图形软件将生成的EMF数据复制到剪切板的过程:

 1 //请复制到MSPaint或Word查看。
 2 #include <windows.h>
 3 #include <stdio.h>
 4 #include <stdlib.h>
 5 #define Random (rand()%256)
 6 void DrawEMF(HDC hdc)
 7 {
 8     RECT rect;
 9     static HFONT hFont;
10     int h=24;
11     hFont=CreateFont(h,0,0,0,0,0,0,0,1,0,0,0,0,"Consolas");
12     SelectObject(hdc,hFont);
13     char string[]="Hello World!\n你好,世界!Hello World!\n你好,世界!Hello World!\n你好,世界!Hello World!\n你好,世界!";
14     for(int i=0; i<640/h; i++) {
15         SetTextColor(hdc,RGB(Random,Random,Random));
16         TextOut(hdc,0,i*h,string,strlen(string));
17     }
18 }
19 int main()
20 {
21     //像素点的宽和高
22     int width = 1000;
23     int height = 640;
24     int cxMms, cyMms, cxPix, cyPix;
25     HWND hwndClient=GetDesktopWindow();
26     HDC hdc = GetDC(hwndClient);
27     cxMms = GetDeviceCaps (hdc, HORZSIZE);
28     cyMms = GetDeviceCaps (hdc, VERTSIZE);
29     cxPix = GetDeviceCaps (hdc, HORZRES);
30     cyPix = GetDeviceCaps (hdc, VERTRES);
31     ReleaseDC(hwndClient, hdc);
32     // printf("%d %d %d %d\n",cxMms,cyMms,cxPix,cyPix);
33     RECT rcImg= {0,0,(width-1)*cxMms * 100 / cxPix,(height-1)*cyMms * 100 / cyPix};
34     HDC dc = CreateEnhMetaFile(NULL, NULL, &rcImg, (LPSTR)NULL);
35     DrawEMF(dc);
36     HENHMETAFILE hemf= CloseEnhMetaFile(dc);
37     OpenClipboard(0);
38     EmptyClipboard();
39     SetClipboardData(CF_ENHMETAFILE, hemf);
40     CloseClipboard();
41     return 0;
42 }

  使用Ctrl+V粘贴到Word上,导出PDF确认其为矢量图,效果如图所示:

  

2.EPS,PDF和SVG转换为EMF或WMF

  目前能找的方法主要有:Adobe illustrator , Inkscape , Visio。Visio可以将SVG转换为EMF或WMF。Inkscape转换效果一般,且在Windows下运行比较卡。

  Adobe illustrator的失真度应该是最小的。不过,在Word 2016上,我碰巧到的情况是,svg用illustrator导出格式应该是emf,eps和pdf用illustrator导出格式应该是wmf,才能保证最后生成pdf不失真。对于eps和pdf而言,pdf格式对字体的支持更好,可以优先考虑生成pdf,在转成wmf。

  注:Word 2016目前已经支持SVG格式,推荐使用SVG格式。

原文地址:https://www.cnblogs.com/wurui1994/p/6275222.html