Skip to main content
Known Participant
April 23, 2013
Question

InDesign crash while applying character style

  • April 23, 2013
  • 1 reply
  • 839 views

Hi all,

A)I have problem with applying character style to selected text.

when character style is applied to selected text indesign get crashes.

my code snippet is as follow

input parameters

1.RangeData paraRange // start and end index of paragraph

2.storyUIDRef // uidref of current story

          code snippet

          // valid text model

          InterfacePtr<ITextModel> textModel(storyUIDRef, UseDefaultIID());

          if (!textModel)

   break;

          //wax strand

          InterfacePtr<IWaxStrand> waxStrand(((IWaxStrand*)textModel->QueryStrand(kFrameListBoss, IID_IWAXSTRAND)));

          if (waxStrand == nil)

   break;

          //WaxIterator

          K2::scoped_ptr<IWaxIterator> waxIterator(waxStrand->NewWaxIterator());

          if (waxIterator == nil)

    break;

          //first wax line of paragraph

          IWaxLine* waxLine = waxIterator->GetFirstWaxLine(paraRange.Start(nil));

          //iterate each waxline

          while (waxLine != nil && (waxLine->TextOrigin() < paraRange.End()))

          {

    //Iterate for all runs

   K2::scoped_ptr<IWaxRunIterator> waxRunIter( waxLine->QueryWaxRunIterator() ) ;

   IWaxRun * waxRun = waxRunIter->GetFirstRun();

   while (waxRun)

                    {

   int32 startPos  = waxRun->TextOrigin();

   int32 endPos = startPos + waxRun->GetCharCount();

   RangeData textRange(startPos ,endPos);

   ISelectionManager* selMgr = m_activeContext->GetContextSelection();

   if(!selMgr)

    break;

   //get valid textselection suite

  InterfacePtr<ITextSelectionSuite> suite(selMgr, UseDefaultIID());

                              if (!suite)

   break;

                              //select  text

  suite->SetTextSelection(storyRef, textRange, Selection::kScrollIntoView, nil);

                              //created style from selection using  " SnpManipulate::TextStyleCreateStyleFromSelection" method.

                    }

          }

my code get crashed at highlighted text( int32 startPos  = waxRun->TextOrigin();).

B)my next question is how to get textstyle ranges of a selected paragraph.

please help me.

 

Thanks

Tahir

This topic has been closed for replies.

1 reply

Inspiring
July 24, 2013

A) Make sure that the all parcels of the text is composed before you iterate it, see ITextParcelListComposer. I don't quite understand what you are trying to achieve. You want to apply a character style to a range of text, but the code iterates wax lines and iterate the runs of each line  and sets the current selection to be the run on each iteration. Why not just:

InterfacePtr<ICommand> icmd(textmodelCmds->ApplyStyleCmd(index, length,styleUID,kCharAttrStrandBoss,kFalse));

B) Walk the kCharAttrStrands to the get information:

InterfacePtr<IStrand> strand((IStrand*)textmodel->QueryStrand(kCharAttrStrandBoss,IStrand::kDefaultIID));

then call stand->GetRunLength() a number of times until, you are through the selected part of the text / paragraph