Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

How To Set Justification Settings

Community Beginner ,
Jun 29, 2009 Jun 29, 2009

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

TOPICS
SDK
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Jul 01, 2009 Jul 01, 2009

Treat existing attributes that you obtained via Query...() as readonly.

For changes use a command. See BuildApplyTextAttrCmd, e.g. in Mike's post.

Dirk

Translate
Advocate ,
Jun 29, 2009 Jun 29, 2009
Like always it is helpful to first see how things work in the UI, learn the appropriate terminology from there, and then start coding. What you call settings of a paragraph, is stored as attributes. There are multiple competing places to store attributes - the styles, nested styles, local overrides.
The kComposeStyleBoss is an intermediate/temporary structure that holds a copy of all the effective values of those attributes, e.g. for use by composers. Unless you're implementing an own attribute, you should not modify that structure.
If your use case involves the selection, use the ITextAttributeSuite, otherwise have a look at ITextAttrUtils.
Dirk
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jun 29, 2009 Jun 29, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 01, 2009 Jul 01, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jul 01, 2009 Jul 01, 2009

Treat existing attributes that you obtained via Query...() as readonly.

For changes use a command. See BuildApplyTextAttrCmd, e.g. in Mike's post.

Dirk

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 01, 2009 Jul 01, 2009
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines