Adobe text engine提供了Illustrator中强大的文本支持,主要的特点有:
1. unicode
2. OpenType
3. 先进的排版技术,如字距、边缘对齐、自动的字形替换、字形比例。
4. 文本和段落样式
5. 亚洲文字
下面就是一些使用ATE的方法。
创建point text:
ASErr SnpText::CreatePointText()
{
ASErr result = kNoErr;
try {
// Get the group art that contains all the art in the current layer.
AIArtHandle artGroup = NULL;
result = sAIArt->GetFirstArtOfLayer(NULL, &artGroup);
aisdk::check_ai_error(result);
// Add the new point text item to the layer. 添加point text
AITextOrientation orient = kHorizontalTextOrientation;
AIRealPoint anchor = {10,10};
AIArtHandle textFrame = NULL;
result = sAITextFrame->NewPointText(kPlaceAboveAll, artGroup, orient, anchor, &textFrame);
aisdk::check_ai_error(result);
// Set the contents of the text range. 改变内容
TextRangeRef range = NULL;
result = sAITextFrame->GetATETextRange(textFrame, &range);
aisdk::check_ai_error(result);
ITextRange crange(range);
crange.InsertAfter("New point text item");
}
catch (ai::Error& ex) {
result = ex;
}
catch (ATE::Exception& ex) {
result = ex.error;
}
return result;
}
创建In path text:
ASErr SnpText::CreateInPathText()
{
ASErr result = kNoErr;
try {
// Get the group art that contains all the art in the current layer. 获取组art
AIArtHandle artGroup = NULL;
result = sAIArt->GetFirstArtOfLayer(NULL, &artGroup);
aisdk::check_ai_error(result);
// Add the new in path text item to the layer.
AIArtHandle textFrame;
sAIArt->GetArtFirstChild(artGroup, &textFrame); // 我先创建了一个矩形矿,这里是获取这个矩形框
aisdk::check_ai_error(result);
AITextOrientation orient = kHorizontalTextOrientation;
result = sAITextFrame->NewInPathText(kPlaceAboveAll, artGroup, orient, textFrame, NULL, false, &textFrame);
aisdk::check_ai_error(result);
// Set the contents of the text range. 改变内容
TextRangeRef range = NULL;
result = sAITextFrame->GetATETextRange(textFrame, &range);
aisdk::check_ai_error(result);
ITextRange iTextRange(range);
iTextRange.InsertAfter("New in path text item");
}
catch (ai::Error& ex) {
result = ex;
}
catch (ATE::Exception& ex) {
result = ex.error;
}
return result;
}
ASErr SnpText::CreateOnPathText()
{
ASErr result = kNoErr;
try {
// Get the group art that contains all the art in the current layer.
AIArtHandle artGroup = NULL;
result = sAIArt->GetFirstArtOfLayer(NULL, &artGroup);
aisdk::check_ai_error(result);
// Add the new on path text item to the layer.
AITextOrientation orient = kHorizontalTextOrientation;
AIArtHandle textPath;
sAIArt->GetArtFirstChild(artGroup, &textPath); // 先创建了一个圆弧,这里是获取这个圆弧
aisdk::check_ai_error(result);
result = sAITextFrame->NewOnPathText(kPlaceAboveAll, artGroup, orient, textPath, 0, 0, NULL, false, &textPath);
aisdk::check_ai_error(result);
// Set the contents of the text range.
TextRangeRef range = NULL;
result = sAITextFrame->GetATETextRange(textPath, &range);
aisdk::check_ai_error(result);
ITextRange iTextRange(range);
iTextRange.InsertAfter("New on path text item");
}
catch (ai::Error& ex) {
result = ex;
}
catch (ATE::Exception& ex) {
result = ex.error;
}
return result;
}