C#调用Illustrator CS4生成系统所有字体列表并保存为AI文件(Illustrator矢量图形编程之4)
2009-01-04 17:34
811 查看
本篇讲述C#调用Illustrator CS4生成系统所有字体列表并保存为AI文件,作为前几篇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。
参考资源:
如果你对C#下的Illustrator编程感兴趣,可以再看看这两篇:
用C#对Illustrator矢量图形软件进行编程之1 http://blog.csdn.net/johnsuna/archive/2008/04/05/2252514.aspx
用C#对Illustrator矢量图形软件进行编程之2 http://blog.csdn.net/johnsuna/archive/2008/04/10/2279817.aspx
C#调用Illustrator生成矢量图的缩略图(Illustrator矢量图形编程之3) http://blog.csdn.net/johnsuna/archive/2009/01/03/3692188.aspx
本文的重点在于如何取得字体列表,如何对文字输出的格式、大小进行控制,最后又是如何保存为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。
参考资源:
如果你对C#下的Illustrator编程感兴趣,可以再看看这两篇:
用C#对Illustrator矢量图形软件进行编程之1 http://blog.csdn.net/johnsuna/archive/2008/04/05/2252514.aspx
用C#对Illustrator矢量图形软件进行编程之2 http://blog.csdn.net/johnsuna/archive/2008/04/10/2279817.aspx
C#调用Illustrator生成矢量图的缩略图(Illustrator矢量图形编程之3) http://blog.csdn.net/johnsuna/archive/2009/01/03/3692188.aspx
相关文章推荐
- C#调用Illustrator CS4生成系统所有字体列表并保存为AI文件(Illustrator矢量图形编程之4)
- C#调用Illustrator生成矢量图的缩略图(Illustrator矢量图形编程之3)
- VC编程调用dxdiag生成XML文件,来获取系统配置情况
- c# asp.net 调用系统设置字体文本框,设置label或页面字体,大小,FontDialog
- C#中获取当前系统中安装的所有字体及预定义颜色
- UNIX环境高级编程——Linux系统调用列表
- 黄聪:C#获取系统中的所有字体
- UNIX环境高级编程——Linux系统调用列表
- C#保存EMF矢量图形文件
- C#中获取当前系统中安装的所有字体及预定义颜色
- UNIX环境高级编程——Linux系统调用列表
- 信息管理系统开发架构 配置实现列表展示分析图形及编辑等 构建信息分析展示平台 C#快速开发架构
- 转载:c#如何获取当前系统所有的字体和颜色?
- c# asp.net 调用系统设置字体文本框
- GDI(图形设备接口)编程(三)系统字体与字符尺寸
- c# asp.net 调用系统设置字体文本框
- C# 生成Excel 并保存 包含web和winform调用方法
- C#中获取当前系统中安装的所有字体及预定义颜色
- 找出系统中所有以user0开头并且是可以登录和没有密码的用户,并生成文本文件保存。
- Android调用系统相机拍照并保存图片文件