摘要:本Illustrator教程讲述C#调用Illustrator CS4生成系统所有字体列表并保存为AI文件,作为前几篇Illustrator矢量图形编程系列的续篇。本Illustrator教程的重点在于如何取得字体列表,如何对文字输出的格式、大小进行控制,最后又是如何保存为Illustrator的不同版本的。
Illustrator教程之用C#对Illustrator矢量图形软件进行编程4
本Illustrator教程讲述C#调用Illustrator CS4生成系统所有字体列表并保存为AI文件,作为前几篇Illustrator矢量图形编程系列的续篇。本Illustrator教程的重点在于如何取得字体列表,如何对文字输出的格式、大小进行控制,最后又是如何保存为Illustrator的不同版本的。
先看运行之后的效果图:
下面看看C#处理的代码:
private void btnChangeWords_Click(object sender, EventArgs e) { Illustrator.Application app = new Illustrator.Application(); // 文档的尺寸,Illustrator默认为以Point(磅)为单位,所以下面的涉及尺寸度量的,都是Point为单位。做过印刷或广告的朋友应该知道,72Points=1英寸,即2.54cm。 double myWidth = 888.0; double myHeight = 400.0; Illustrator.Document docRef = app.Documents.Add(null, myWidth, myHeight, null, null, null, null); // 边距 double edgeSpacing = 14; // 栏间距 double columnSpacing = 268; double x = edgeSpacing; double y = docRef.Height - edgeSpacing; double iCounter = 0; try { // 这里通过Illustrator.Application的实例app的TextFonts找到所有字体列表 foreach (Illustrator.TextFont fontRef in app.TextFonts) { // 通过Document实例的TextFrames.Add()方法增加文字 Illustrator.TextFrame textRef = docRef.TextFrames.Add(); // 文字的大小 textRef.TextRange.CharacterAttributes.Size = 14; // 文字的内容 textRef.Contents = fontRef.Name + " | " + fontRef.Style.ToString(); textRef.Top = y; //垂直方向的位置 textRef.Left = x; //水平方向的位置 // 如果大于文档尺寸,则不输出,主要目的是想叙述控制的方法 if ((x + textRef.Width) > docRef.Width) { textRef.Delete(); continue; } // 设置字体 textRef.TextRange.CharacterAttributes.TextFont = app.TextFonts[fontRef.Name]; // 控制输出的总高度 y = y - textRef.Height; if (y < 28) { y = docRef.Height - edgeSpacing; x = x + columnSpacing; } iCounter = iCounter + 1; // 这里只列出60条,如果需要更多,可以修改下句代码 if (iCounter > 60) break; } } catch (Exception excOuter) { excOuter = null; } // AI格式文档保存选项 Illustrator.IllustratorSaveOptions saveOptions = new Illustrator.IllustratorSaveOptions(); saveOptions.Compatibility = Illustrator.AiCompatibility.aiIllustrator11;//设置保存文件的版本,比如你可以使用aiIllustrator8等。 saveOptions.FlattenOutput = Illustrator.AiOutputFlattening.aiPreserveAppearance; // 保存AI文件 docRef.SaveAs(@"F:/Johnson/IllustratorDemo/Fonts.ai", saveOptions); docRef = null; }
OK。
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注常用软件Illustrator频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号