Text is not getting shown via API; even though it's getting saved.
Hi,
I'm experiencing a very unusual issue when try ing to create and display text via the Adobe Text Engine API. Please see the steps below explaining the scenario
Step 1: Opening the .ai file a first time in order to test the plugin.
Text for the following fields should be created and displayed (but it's not)
- Substrate
- Note
- Color Station
- Date Created
- Author
Also, text for File Name should be removed, but it's not.
Step 2: Deleting the plugin.
In order to confirm that the plugin code doesn't rerun, I deleted it before reopening the .ai file to see if any changes were saved.
Step 3: Reopening the .ai file without the plugin to check if the changes were saved
As seen below, all text fields to be shown were actually saved and the file name was removed too.
It all seemed to work fine previously and I'm puzzled by this! Any help would be truly appreciated!
Here's the code snippet I've used:
ATE::ICharFeatures features;
FontRef fontRef;
AIFontKey fontKey;
features.SetFontSize(10);
AIArtHandle newFrame;
SnpArtHelper artHelper;
/*
CODE FOR REMOVING TEXT
...............................................
*/
if (bClearTextFields)
{
if (tmpFontSize == fontSize)
{
// Remove the text if the font size matches the configured one!
textRange.Remove();
}
}
/*
CODE FOR CREATING TEXT
...............................................
*/
// 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.
AITextOrientation orient = kHorizontalTextOrientation;
AIArtHandle textFrame = NULL;
result = sAITextFrame->NewPointText(kPlaceAboveAll, artGroup, orient, newAnchor, &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);
string text = "1";
crange.SetLocalCharFeatures(features);
crange.InsertAfter(ai::UnicodeString(text).as_ASUnicode().c_str());
/*
CODE FOR SAVING THE FILE
...................................
*/
// TODOs: Ask client if the file is to be autosaved.
boolean bAutoSaveFile = true;
if (bAutoSaveFile)
{
// Save the .AI file once showing
AIDocumentHandle documentHandle;
sAIDocument->GetDocument(&documentHandle);
sAIDocumentList->Save(documentHandle);
}