Skip to main content
3DTOPO
Inspiring
March 26, 2008
Question

Single TextRange ArtStyle/CharStyle?

  • March 26, 2008
  • 2 replies
  • 924 views
Greetings,

I can apply a art style to a whole text object with:

AIArtStyleHandle artStyle;
AIArtHandle textHandle;

error = sAIArtStyle->SetArtStyle ( textHandle, artStyle );

However I cannot find a way to apply an ArtStyle or CharStyle to an individual TextRange. Using sAIArtStyle->SetArtStyle sets all of the TextRanges in the text art handle to a single style. I am sure it must be possible because I can apply multiple Art Styles to a single text object manually...

Any help would be greatly appreciated.

Thanks,

-jeshua
This topic has been closed for replies.

2 replies

3DTOPO
3DTOPOAuthor
Inspiring
March 26, 2008
Hello JLG,

Thanks for your detailed post. I realize that I can apply different fonts, color, size, etc. to a single text run, however, I really need to figure out how to apply ArtStyles and CharStyles to the ranges.

If it can't be done, I guess I will have to create a work-around which would look up all of the features of a given style and apply it. The downside of this approach is that the range will not be associated with the style (with Illustrator's built-in features like select by style) which is a major drawback for the workflow that I have created.

The system that I have created uses the styles as an attribute. While the style name could be preserved in the artwork's dictionary it really complicates things and is far from ideal.

Thanks again,

-jeshua
Participating Frequently
March 26, 2008
Hi,

I had the same problem and here is a possible solution.

This example create a point text object.
The text color is modified and the result is a black, cyan, magenta and yellow text.
It's possible to adapt it to modify the size, the font, the justification etc, inside a single text object.

//In your main program

//Text position.
AIRealPoint TextPosition;
TextPosition.h=400;
TextPosition.v=300;

//Creation of the text object with the AITextFrameSuite.
//For instance, the point text object will be created above all at textPosition.
AIArtHandle Texte;
error = sAITextFrame->NewPointText(kPlaceAboveAll, nil, kHorizontalTextOrientation, TextPosition, &textHandle);
//Call the ModifyTextColor.
error=ModifyTextColor(textHandle);


//Copy these lines.
//The result will be a point text object with different colors.
//With the same method, it's possible to modify everything inside a text.

extern AIErr ModifyTextColor(AIArtHandle textHandle)
{AIErr error=kNoErr;
TextRangeRef textRange;
ATE::ApplicationPaintRef ATECouleurRef;
ATE::IParaFeatures justif;
ATE::ICharFeatures features;
FontRef fontRef;
AIFontKey fontKey;
AIColor mycolor;

error = sAITextFrame->GetATETextRange(textHandle, &textRange );
if (!error )
{ATE::ITextRange iTextRange( textRange );

iTextRange.Remove();

justif.SetLeadingType(ATE::kRomanLeadingType);
justif.SetStartIndent(kAIRealZero);
justif.SetFirstLineIndent(kAIRealZero);
features.SetTracking(kAIRealZero);
//Justification.
justif.SetJustification(ATE::kCenterJustify);
//Size.
features.SetFontSize(16);

//The text itself.
iTextRange.InsertAfter("http://perso.orange.fr/jlg.outils");

//Text color. All the text is black.
mycolor.kind=kFourColor;
mycolor.c.f.cyan=1;
mycolor.c.f.magenta=1;
mycolor.c.f.yellow=1;
mycolor.c.f.black=1;
error = sATEPaint->CreateATEApplicationPaint(&mycolor, &ATECouleurRef);
features.SetFillColor(ATE::IApplicationPaint(ATECouleurRef));

//The text characteristics are applied.
iTextRange.SetLocalCharFeatures(features);
iTextRange.SetLocalParaFeatures(justif);

//Cyan color for a few chars.
mycolor.kind=kFourColor;
mycolor.c.f.cyan=1;
mycolor.c.f.magenta=0;
mycolor.c.f.yellow=0;
mycolor.c.f.black=0;
error = sATEPaint->CreateATEApplicationPaint(&mycolor, &ATECouleurRef);

ATE::IStory myStory=iTextRange.GetStory();

ATE::ITextRange myRange;

myRange = myStory.GetTextRange(7, 16);
features.SetFillColor(ATE::IApplicationPaint(ATECouleurRef));
myRange.SetLocalCharFeatures(features);
//Magenta color for a few chars.
mycolor.c.f.cyan=0;
mycolor.c.f.magenta=1;
error = sATEPaint->CreateATEApplicationPaint(&mycolor, &ATECouleurRef);
myRange = myStory.GetTextRange(13, 19);

features.SetFillColor(ATE::IApplicationPaint(ATECouleurRef));
myRange.SetLocalCharFeatures(features);

//Yellow color for a few chars.
mycolor.c.f.magenta=0;
mycolor.c.f.yellow=1;
error = sATEPaint->CreateATEApplicationPaint(&mycolor, &ATECouleurRef);
myRange = myStory.GetTextRange(27, 33);

features.SetFillColor(ATE::IApplicationPaint(ATECouleurRef));
myRange.SetLocalCharFeatures(features);

}

error:
return error;
}

I hope this will be useful.

JLG.