Copy link to clipboard
Copied
Hi,
I'm trying to set the justification settings of a paragraph using IJustificationStyle's different setter mehods but the paragraph does not reflect the change that I set into the setter methods. I can see using the IJusificationStyle->GetWordspace method that the value was changed.
I tried recomposing the wax using IFramelistComposer->RecomposeThruNthFrame() method after setting the values but still the paragraph won't reflect the change in values.
Any help is highly appreciated, thanks!
-- Jeff
Treat existing attributes that you obtained via Query...() as readonly.
For changes use a command. See BuildApplyTextAttrCmd, e.g. in Mike's post.
Dirk
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I wrote this code soemtime ago for CS4 it reverses the alignment of all the text in a textFrame but could easily be modified to operate on a paragraph.
//========================================================
// ReverseTextAlignment
// Change the text alignment in the text frame from leftAlign to rightAlign or leftJustify to rightJustify.
//========================================================
void PageItemFlipper::ReverseTextAlignment(UIDRef textFrameRef)
{
do {
// get the text content UID
UID textContentUID = kInvalidUID;
InterfacePtr <IGraphicFrameData> frameData(textFrameRef, UseDefaultIID());
if (frameData) {
textContentUID = frameData->GetTextContentUID();
}
IDataBase* database = textFrameRef.GetDataBase();
InterfacePtr <IMultiColumnTextFrame> mctf(database, textContentUID, UseDefaultIID());
if (mctf == nil) { this->logger->Error("Nil multi column text object."); break; }
InterfacePtr <ITextModel> textModel(mctf->QueryTextModel());
if (textModel == nil) { this->logger->Error("Nil text model object."); break; }
// get the number of characters in the story. Theres always a terminating character so
// if the character length is not greator than 1 say goodbye.
int32 characterCount = textModel->GetPrimaryStoryThreadSpan();
if (characterCount <= 1) { break; }
// get the range of characters in the story
int32 textSpan = mctf->TextSpan();
TextIndex startIndex = mctf->TextStart();
TextIndex endIndex = startIndex + textSpan;
// Check if the frame displays the stories terminating character
if (endIndex >= characterCount) {
textSpan--;
endIndex--;
}
if (textSpan <= 0) { break; }
RangeData tRange(startIndex, endIndex);
InterfacePtr <IComposeScanner> composer(textModel, IID_ICOMPOSESCANNER);
if (composer == nil) { this->logger->Error("Nil ComposeScanner object."); break; }
IDrawingStyle* drawingStyle = composer->GetCompleteStyleAt(startIndex, &textSpan);
if (drawingStyle == nil) { this->logger->Error("Nil DrawingStyle object."); break; }
InterfacePtr <ICompositionStyle> compStyle(drawingStyle, IID_ICOMPOSITIONSTYLE);
if (compStyle == nil) { this->logger->Error("Nil CompositionStyle object."); break; }
// get the alignment applied to the text range
ICompositionStyle::TextAlignment appliedAlignment = compStyle->GetParagraphAlignment();
ICompositionStyle::TextAlignment newAlignment = this->GetNewAlignmentValue(appliedAlignment);
// change the alignment (values see ICompositionStyle alignment enum)
InterfacePtr <ITextAttrAlign> alignAttribute1(CreateObject2<ITextAttrAlign>(kTextAttrAlignmentBoss));
InterfacePtr <ITextAttrAlign> alignAttribute2(CreateObject2<ITextAttrAlign>(kTextAttrAlignmentBoss));
if (alignAttribute1 && alignAttribute2) {
alignAttribute1->SetAlignment(newAlignment);
alignAttribute2->SetAlignment(newAlignment);
// create the command to set the alignment attribute
InterfacePtr <ICommand> alignCmd(Utils<ITextAttrUtils>()->BuildApplyTextAttrCmd(textModel, startIndex, (uint)textSpan, alignAttribute1, kParaAttrStrandBoss));
if (alignCmd == nil) { this->logger->Error("Nil alignment command."); break; }
InterfacePtr <IApplyStyleData> cmdAtts(alignCmd, UseDefaultIID());
cmdAtts->GrabOverrides()->ApplyAttribute(alignAttribute2);
ErrorCode result = CmdUtils::ProcessCommand(alignCmd);
if (result == kFailure) {
this->logger->Error("Reversing alignment failed...");
}
}
} while (kFalse);
}
Hope it helps.
mike
Copy link to clipboard
Copied
I used the ITextAttrUtils approach using:
AttributeBossList attrList;
Utils<ITextAttrUtils>()->GetTotalAttributesAtIndex(textModel, startIndex, kFalse, kFalse, attrList);
InterfacePtr<ITextAttrRealNumber> attrWordMin((ITextAttrRealNumber *)attrList.QueryByClassID(kTextAttrWordspaceMinBoss, ITextAttrRealNumber::kDefaultIID));
InterfacePtr<ITextAttrRealNumber> attrWordDes((ITextAttrRealNumber *)attrList.QueryByClassID(kTextAttrWordspaceDesBoss, ITextAttrRealNumber::kDefaultIID));
InterfacePtr<ITextAttrRealNumber> attrWordMax((ITextAttrRealNumber *)attrList.QueryByClassID(kTextAttrWordspaceMaxBoss, ITextAttrRealNumber::kDefaultIID));
if (attrWordMin == nil || attrWordDes == nil || attrWordMax == nil) break;
PMReal wordMin, wordDes, wordMax;
wordMin = attrWordMin->GetRealNumber();
wordDes = attrWordDes->GetRealNumber();
wordMax = attrWordMax->GetRealNumber();
wordMax -= fMaxValue;
wordDes -= fMaxValue;
wordMin -= fMaxValue;
attrWordMax->SetRealNumber(wordMax);
attrWordDes->SetRealNumber(wordDes);
attrWordMin->SetRealNumber(wordMin);
attrList.ApplyAttribute(attrWordMax);
attrList.ApplyAttribute(attrWordDes);
attrList.ApplyAttribute(attrWordMin);
This sets the justification settings properly, however I'm getting assert messages:
kStyleBoss[TextPrefix + 5 (0x205)]:kTextAttributeListImpl[TextPrefix + 63 (0x23f)] chnaged but not marked dirty. Byte 723 of 5248 was 0x0 now 0xa
How can I resolve this?
Thanks,
-- Jeff
Copy link to clipboard
Copied
Treat existing attributes that you obtained via Query...() as readonly.
For changes use a command. See BuildApplyTextAttrCmd, e.g. in Mike's post.
Dirk
Copy link to clipboard
Copied
That did it... Thanks!
I created an AttributeBossList and then applied the attribute on this new list. I then used this for the BuildApplyTextAttrCmd.
-- Jeff
Find more inspiration, events, and resources on the new Adobe Community
Explore Now