Skip navigation
Currently Being Moderated

Set Color for Text

Jul 31, 2008 12:26 AM

Hi,<br /><br />we need something to set the color for text i'm adding. I use the CHMLFiltTextHelper to add text so i decided to add a function AddColor there.<br /><br />so i searched the sdk samples, found some code about setting the color (SnpApplyTextStyleAttributes.cpp) and i wrote this function:<br /><br />>void CHMLFiltTextHelper::AddColor( const double red , const double green , const double blue ) <br />{<br />  this->checkInvariant();<br />     InterfacePtr<ITextAttrUID> textAttrUID_Color(::CreateObject2<ITextAttrUID>(kTextAttrColorBoss)); <br />     if (textAttrUID_Color != nil) {<br />       const int32 colorSpace = ( kPMCsCalRGB );     // RGB color space.<br />          ColorArray rgbColor;<br />               <br />>          rgbColor.push_back( red ); // Red (0.0...1.0)<br />          rgbColor.push_back( green ); // Green (0.0...1.0)<br />          rgbColor.push_back( blue ); // Blue (0.0...1.0)<br />               <br />>    InterfacePtr<ICommand> newColorCmd( CmdUtils::CreateCommand( kNewColorCmdBoss ) );<br />               <br />>          if( newColorCmd != nil ) {<br />               InterfacePtr<IColorData> colorData(newColorCmd, UseDefaultIID());<br />               if( colorData ) {<br />b                 // Indesign crashed in the next line<br />                    colorData->SetColorData( rgbColor );<br /><br />>                    ErrorCode error = CmdUtils::ProcessCommand(newColorCmd);<br />                    if (error == kSuccess) {<br />                         const UIDList* colorUIDList = newColorCmd->GetItemList();<br />                         if (colorUIDList != nil) {<br />                              UID colorUID = colorUIDList->First();<br />                              textAttrUID_Color->SetUIDData( colorUID );<br />                              ASSERT(this->fCharAttributeBossList); <br />                              this->fCharAttributeBossList->ApplyAt tribute( textAttrUID_Color );<br />                         }<br />                    }<br />               }<br />          }<br />  }<br />}<br /><br />But it doesn't work, InDesign crashed at this line:<br />>                     colorData->SetColorData( rgbColor );<br /><br />What is wrong here?<br /><br />Thanks<br />Klaus<br /><br />PS: The Forum kills all the indents in the code, hope it is readable ..
 
Replies
  • Currently Being Moderated
    Jul 31, 2008 3:49 AM   in reply to (Klaus_Friese)
    I guess (in other words, did not try) the size of the array does not match the requirements of the preset color space. See the comment on SetColorData, even if it is phrased a bit weak "Typically color space is set first ...".

    Dirk
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 31, 2008 3:52 AM   in reply to (Klaus_Friese)
    Regarding indents, see here:
    http://www.adobeforums.com/webx?128@@.3bc170eb
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 24, 2012 8:45 AM   in reply to (Klaus_Friese)

    I may be a little bit late, but try this :

     

    ErrorCode MyTextUtils::ApplyTextAttributes(ITextModel * textModel, int32 position, int32 length, UID attributeUID, ClassID classID)

    {

      ErrorCode rc = kFailure;

      do {

           InterfacePtr<ITextAttrUID> textAttrUID(::CreateObject2<ITextAttrUID>(classID));

     

           // Set our color attribute and store it:

           textAttrUID->SetUIDData(attributeUID);

     

           InterfacePtr<ICommand> pApplyTextAttrCmd ( Utils<ITextAttrUtils>()->BuildApplyTextAttrCmd(textModel, position,  length, textAttrUID, kCharAttrStrandBoss));   

            rc = CmdUtils::ProcessCommand(pApplyTextAttrCmd);

     

        } while(false);

     

        return rc;              

    }

     

     

    Use kTextAttrColorBoss for the classID, and the UID of your color for attributeUID

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)