InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TextAttrScriptUtility Class Reference

#include <TextAttrScriptUtility.h>

Public Member Functions

 TextAttrScriptUtility (IScript *script, const RequestContext &context, IScript *target=nil)
 
 TextAttrScriptUtility (const AttributeBossList *attributeBossList, const RequestContext &context)
 
ErrorCode AccessBoolAttribute (IScriptRequestData *data, const ScriptID &propID, const ClassID &attrClass)
 
ErrorCode AccessInt16Attribute (IScriptRequestData *data, const ScriptID &propID, const ClassID &attrClass)
 
ErrorCode AccessInt32Attribute (IScriptRequestData *data, const ScriptID &propID, const ClassID &attrClass)
 
ErrorCode AccessUnitAttribute (IScriptRequestData *data, const ScriptID &propID, const ClassID &attrClass, ScriptData::UnitType unitType)
 
ErrorCode AccessRealAttribute (IScriptRequestData *data, const ScriptID &propID, const ClassID &attrClass)
 
ErrorCode AccessPercentageAttribute (IScriptRequestData *data, const ScriptID &propID, const ClassID &attrClass)
 
ErrorCode AccessColor (IScriptRequestData *data, const ScriptID &propID, const ClassID &attrClass, const bool16 useTextColor=kTrue)
 
ErrorCode AccessLineTypeAttribute (IScriptRequestData *data, const ScriptID &propID, const ClassID &attrClass)
 
ErrorCode AccessFont (IScriptRequestData *data, const ScriptID &propID, const ClassID &fontClass, const ClassID &styleClass, const ClassID &strand=kCharAttrStrandBoss, bool16 returnFontName=kFalse)
 
ErrorCode AccessFontStyle (IScriptRequestData *data, const ScriptID &propID, const ClassID &fontClass, const ClassID &styleClass, const ClassID &strand=kCharAttrStrandBoss)
 
ErrorCode GetAttributeReport (const ClassID &attrClass, InterfacePtr< const IAttrReport > &attrReport)
 
ErrorCode AddAttribute (const IPMUnknown *addAttr, IDataBase *targetDB=nil)
 
ErrorCode AddAttributes (const AddAttributeList &addAttrList, IDataBase *targetDB=nil)
 
ErrorCode RemoveAttribute (const ClassID &removeAttr)
 
ErrorCode RemoveAttributes (const RemoveAttributeList &removeAttrList)
 
ErrorCode ApplyScriptCmd ()
 
ErrorCode AccessDesignAxes (IScriptRequestData *data, const ScriptID &propID, const ClassID &fontClass, const ClassID &styleClass, const ClassID &strand=kCharAttrStrandBoss)
 
ErrorCode SetNthDesignAxis (IScriptRequestData *data, IScript *script, const ClassID &fontClass, const ClassID &styleClass, const ClassID &strand=kCharAttrStrandBoss)
 
ErrorCode IsNthDesignAxisHidden (IScriptRequestData *data, IScript *script, const ClassID &fontClass, const ClassID &styleClass)
 

Protected Member Functions

IScriptGetScript () const
 
IScriptGetTargetScript () const
 
const ScriptIDGetObjectType () const
 
void CacheCurrentAttrs ()
 
ErrorCode AccessMultiplierAttribute (IScriptRequestData *data, const ScriptID &propID, const ClassID &attrClass, const PMReal &multiplier)
 
bool16 IsFindChangeObject (const ScriptID &objectType)
 
IFontFamilyQueryFontFamilyFromScript (IScriptRequestData *data, const ScriptID &propID, PMString fontStyle)
 
IFontFamilyQueryFontFamilyFromModel (IScriptRequestData *data, const ClassID &fontClass, PMString fontStyle)
 

Detailed Description

Text attribute utility class

This utility class helps handle the common details of how Text Attributes are processed for scripting objects. Due to the wide variety of scripting objects that have Text Attributes of some sort this ensures that we have a consistent handling of them across all the scripting objects. However, there is no way at the present time to extensibly add new types scripting objects to this implementation.

The constructor takes a IScript object with any of following properties (in order of priority):

It implements the IID_ITEXTMODEL interface (typically the kTextStoryBoss)

    (and IID_ICOMPOSESCANNER)

It implements the IID_ITEXTTARGET interface (typically something inheriting

    from the kTextScriptingSuiteBoss)

It implements the IID_ITEXTITERSCRIPTDATA interface (used by IDML)

It implements the IID_ISTYLEINFO interface (character/paragraph styles)

It is a c_FindPref or c_FindTextPref Script object type

It is a c_ChangePref or c_ChangeText Script object type

It is a c_FindGrepPref Script object type

It is a c_ChangeGrepPref Script object type

It is a c_FindTransliteratePref Script object type

It is a c_ChangeTransliteratePref Script object type

It is a c_TextDefault Script object type

IT is a c_FindGlyphPref Script object type

IT is a c_ChangeGlyphPref Script object type

The simplest usage pattern looks like this:

ErrorCode MyProvider::AccessMyBoolAttr(ScriptID propID, IScriptRequestData* data, IScript* script)

{

    TextAttrScriptUtility tasu(script, script, data->GetRequestContext());

    const ClassID attrID = kMyBoolAttributeBoss;

    ErrorCode err = tasu.AccessBoolAttribute(data, propID, attrID);

    if ( err == kSuccess && data->IsPropertyPut())

        err = tasu.ApplyScriptCmd();

    return err ;

}

For those implementations that have more than one TextAttribute it is much more efficient for INX and IDML purposes if this is wired up via PreAccessProperty() and PostAccessProperty() like so:

class MyProvider : ...

{

    private:

        scoped_ptr<TextAttrScriptUtility>  tasu;



}



ErrorCode MyProvider::PreAccessProperty(ScriptID propID, IScriptRequestData* data, IScript* script)

{

    tasu.reset(new TextAttrScriptUtility(script));

    return kSuccess;

}



ErrorCode MyProvider::PostAccessProperty(ScriptID propID, IScriptRequestData* data, IScript* script)

{

    ASSERT(tasu != nil);

    ErrorCode err = kSuccess;

    if (data->IsPropertyPut())

        err = tasu->ApplyScriptCmd(data);

    tasu.reset() ;

    return err;

}



To remove an attribute pass in en_Nothing for scriptData.

Constructor & Destructor Documentation

TextAttrScriptUtility::TextAttrScriptUtility (IScriptscript,
const RequestContextcontext,
IScripttarget = nil 
)

Construct a new TextAttrScriptUtility

Parameters
scriptPointer to script boss, see comments at top of file. is the target object that has text attributes you plan to get or set

Member Function Documentation

ErrorCode TextAttrScriptUtility::AccessBoolAttribute (IScriptRequestDatadata,
const ScriptIDpropID,
const ClassIDattrClass 
)

AccessBoolAttribute. Get/Set a boolean attribute.

Parameters
dataPointer to IScriptRequestData.
propIDScriptID of the property to be accessed.
attrClassBoss must implement IID_ITEXTATTRBOOLEAN
Returns
kSuccess if successful or returns an error code.
ErrorCode TextAttrScriptUtility::AccessColor (IScriptRequestDatadata,
const ScriptIDpropID,
const ClassIDattrClass,
const bool16 useTextColor = kTrue 
)

AccessColor. Get/Set a color attribute.

Parameters
dataPointer to IScriptRequestData. Accepts "Text Color", swatch object or en_Nothing on set, returns "Text Color" string or swatch object on get.
propIDScriptID of the property to be accessed.
attrClassBoss must implement IID_ITEXTATTRUID
useTextColor- typically text attributes for color allow "Text Color" string as valid value, clients can configure to not allow "Text Color" for a particular attribute.
Returns
kSuccess if successful or returns an error code.
ErrorCode TextAttrScriptUtility::AccessDesignAxes (IScriptRequestDatadata,
const ScriptIDpropID,
const ClassIDfontClass,
const ClassIDstyleClass,
const ClassIDstrand = kCharAttrStrandBoss 
)

AccessDesignAxes

Parameters
datadata Pointer to IScriptRequestData expected to contain design axes of variable font.
propIDScriptID of the property to be accessed, should be p_DesignAxes.
fontClassBoss must implement IID_ITEXTATTRUID
styleClassBoss must implement IID_ITEXATTRUID
strandOne of kCharAttrStrandBoss or kParaAttrStrandBoss
Returns
kSuccess if successful or returns an error code.
ErrorCode TextAttrScriptUtility::AccessFont (IScriptRequestDatadata,
const ScriptIDpropID,
const ClassIDfontClass,
const ClassIDstyleClass,
const ClassIDstrand = kCharAttrStrandBoss,
bool16 returnFontName = kFalse 
)

AccessFont. Get/Set a font attribute.

Parameters
dataPointer to IScriptRequestData.
propIDScriptID of the property to be accessed.
fontClassBoss must implement IID_ITEXTATTRUID
styleClassBoss must implement IID_ITEXATTRUID
strandOne of kCharAttrStrandBoss or kParaAttrStrandBoss
returnFontNameIf kTrue, display family name is returned, otherwise Script object for the font.
Returns
kSuccess if successful or returns an error code.
ErrorCode TextAttrScriptUtility::AccessFontStyle (IScriptRequestDatadata,
const ScriptIDpropID,
const ClassIDfontClass,
const ClassIDstyleClass,
const ClassIDstrand = kCharAttrStrandBoss 
)

AccessFontStyle. Get/Set a font style attribute.

Parameters
dataPointer to IScriptRequestData.
propIDScriptID of the property to be accessed.
fontClassBoss must implement IID_ITEXTATTRUID
styleClassBoss must implement IID_ITEXATTRUID
strandOne of kCharAttrStrandBoss or kParaAttrStrandBoss
Returns
kSuccess if successful or returns an error code.
ErrorCode TextAttrScriptUtility::AccessInt16Attribute (IScriptRequestDatadata,
const ScriptIDpropID,
const ClassIDattrClass 
)

AccessInt16Attribute. Get/Set a int16 attribute.

Parameters
dataPointer to IScriptRequestData.
propIDScriptID of the property to be accessed.
attrClassBoss must implement IID_ITEXTATTRINT16
Returns
kSuccess if successful or returns an error code.
ErrorCode TextAttrScriptUtility::AccessInt32Attribute (IScriptRequestDatadata,
const ScriptIDpropID,
const ClassIDattrClass 
)

AccessInt32Attribute. Get/Set a int32 attribute.

Parameters
dataPointer to IScriptRequestData.
propIDScriptID of the property to be accessed.
attrClassBoss must implement IID_ITEXTATTRINT32
Returns
kSuccess if successful or returns an error code.
ErrorCode TextAttrScriptUtility::AccessLineTypeAttribute (IScriptRequestDatadata,
const ScriptIDpropID,
const ClassIDattrClass 
)

AccessLineTypeAttribute. Get/Set a line type attribute.

Parameters
dataPointer to IScriptRequestData. Calls IPathStrokerUtils::GetStrokeStyleForSetProperty() on set, IPathStrokeUtils::GetStrokeStyleForGetProperty() on get.
propIDScriptID of the property to be accessed.
attrClassBoss must implement IID_ITEXTATTRSTROKETYPE.
Returns
kSuccess if successful or returns an error code.
ErrorCode TextAttrScriptUtility::AccessMultiplierAttribute (IScriptRequestDatadata,
const ScriptIDpropID,
const ClassIDattrClass,
const PMRealmultiplier 
)
protected

AccessMultiplierAttribute

Parameters
dataPointer to IScriptRequestData.
propIDScriptID of the property to be accessed.
attrClassBoss must implement IID_ITEXTATTRREALNUMBER
multiplierReturned values are multiplied by this value, set values are divided by this value.
Returns
kSuccess if successful or returns an error code.
ErrorCode TextAttrScriptUtility::AccessPercentageAttribute (IScriptRequestDatadata,
const ScriptIDpropID,
const ClassIDattrClass 
)

AccessPercentageAttribute. Get/Set a percentage attribute. The implementation calls AccessMultiplierAttribute with a multiplier of 100.0.

Parameters
dataPointer to IScriptRequestData.
propIDScriptID of the property to be accessed.
attrClassBoss must implement IID_ITEXTATTRREALNUMBER
Returns
kSuccess if successful or returns an error code.
ErrorCode TextAttrScriptUtility::AccessRealAttribute (IScriptRequestDatadata,
const ScriptIDpropID,
const ClassIDattrClass 
)

AccessRealAttribute. Get/Set a real number attribute. The implementation calls AccessMultiplierAttribute with a multiplier of 1.0.

Parameters
dataPointer to IScriptRequestData.
propIDScriptID of the property to be accessed.
attrClassBoss must implement IID_ITEXTATTRREALNUMBER
Returns
kSuccess if successful or returns an error code.
ErrorCode TextAttrScriptUtility::AccessUnitAttribute (IScriptRequestDatadata,
const ScriptIDpropID,
const ClassIDattrClass,
ScriptData::UnitType unitType 
)

AccessUnitAttribute. Get/Set a Unit attribute based on a PMReal.

Parameters
dataPointer to IScriptRequestData.
propIDScriptID of the property to be accessed.
attrClassBoss must implement IID_ITEXTATTRREALNUMBER
unitTypeCaller specifies script unit type
Returns
kSuccess if successful or returns an error code.
ErrorCode TextAttrScriptUtility::AddAttribute (const IPMUnknownaddAttr,
IDataBasetargetDB = nil 
)

Add Attribute.

Parameters
addAttrPointer to attribute boss.
targetDBPointer to IDataBase. Only used by FindChange objects.
Returns
kSuccess if successful or returns an error code.
ErrorCode TextAttrScriptUtility::AddAttributes (const AddAttributeList & addAttrList,
IDataBasetargetDB = nil 
)

AddAttributes.

Parameters
addAttrListReference to AttributeBossList
targetDBPointer to IDataBase. Only used by FindChange objects.
Returns
kSuccess if successful or returns an error code.
ErrorCode TextAttrScriptUtility::ApplyScriptCmd ()

ApplyScriptCmd. Apply the attributes added and/or removed.

Returns
kSuccess if successful or returns an error code. Returns kInvalidParameterError if attempting to remove attributes from a text object
void TextAttrScriptUtility::CacheCurrentAttrs ()
protected
CacheCurrentAttrs. The GetAttributeReport() method calls this method

once to cache the attributes for the given script object. It then returns references to the cached attribute bosses.

ErrorCode TextAttrScriptUtility::GetAttributeReport (const ClassIDattrClass,
InterfacePtr< const IAttrReport > & attrReport 
)

GetAttributeReport

Parameters
attrClassBoss must implement IID_IATTRREPORT
attrReportReference to InterfacePtr which will be reset with the boss of the requested class
Returns
kSuccess if successful or returns an error code.
const ScriptID& TextAttrScriptUtility::GetObjectType () const
inlineprotected

GetObjectType

Returns
ScriptID&
IScript* TextAttrScriptUtility::GetScript () const
inlineprotected

GetScript

Returns
IScript*
IScript* TextAttrScriptUtility::GetTargetScript () const
inlineprotected

GetTargetScript

Returns
IScript*
bool16 TextAttrScriptUtility::IsFindChangeObject (const ScriptIDobjectType)
protected

IsFindChangeObject

Parameters
objectTypeto check.
Returns
bool16 kTrue if the the specified ObjectType is one of the following: c_FindPref, c_ChangePref, c_FindTextPref, c_ChangeTextPref, c_FindGrepPref, c_ChangeGrepPref, c_FindTransliteratePref, c_ChangeTransliteratePref, c_FindGlyphPref or c_ChangeGlyphPref. kFalse otherwise.
ErrorCode TextAttrScriptUtility::IsNthDesignAxisHidden (IScriptRequestDatadata,
IScriptscript,
const ClassIDfontClass,
const ClassIDstyleClass 
)

IsNthDesignAxisHidden

Parameters
dataPointer to IScriptRequestData expected to contain index of design axis of variable font.
scriptPointer to script boss, see comments at top of file.
fontClassBoss must implement IID_ITEXTATTRUID
styleClassBoss must implement IID_ITEXTATTRFONT
Returns
kSuccess if successful or returns an error code.
IFontFamily* TextAttrScriptUtility::QueryFontFamilyFromModel (IScriptRequestDatadata,
const ClassIDfontClass,
PMString fontStyle 
)
protected

QueryFontFamilyFromModel

Parameters
dataPointer to IScriptRequestData.
fontClassBoss must implement IID_ITEXTATTRUID
fontStyleIgnored argument
Returns
IFontFamily* Pointer to queried IFontFamily
IFontFamily* TextAttrScriptUtility::QueryFontFamilyFromScript (IScriptRequestDatadata,
const ScriptIDpropID,
PMString fontStyle 
)
protected

QueryFontFamilyFromScript

Parameters
dataPointer to IScriptRequestData expected to contain string type of the display family name.
propIDScriptID of the property to be accessed, should be p_TextFont.
fontStyleDesired style name of the font
Returns
IFontFamily*
ErrorCode TextAttrScriptUtility::RemoveAttribute (const ClassIDremoveAttr)

RemoveAttribute.

Parameters
removeAttrThe ClassID of the attribute to be removed.
Returns
kSuccess if successful or returns an error code.
ErrorCode TextAttrScriptUtility::RemoveAttributes (const RemoveAttributeListremoveAttrList)

RemoveAttributes

Parameters
removeAttrListReference to AttributeBossList containing attributes to be removed.
Returns
kSuccess if successful or returns an error code.
ErrorCode TextAttrScriptUtility::SetNthDesignAxis (IScriptRequestDatadata,
IScriptscript,
const ClassIDfontClass,
const ClassIDstyleClass,
const ClassIDstrand = kCharAttrStrandBoss 
)

AccessDesignAxes

Parameters
datadata Pointer to IScriptRequestData expected to contain index and value of design axis of variable font.
scriptPointer to script boss, see comments at top of file.
fontClassBoss must implement IID_ITEXTATTRUID
styleClassBoss must implement IID_ITEXATTRUID
strandOne of kCharAttrStrandBoss or kParaAttrStrandBoss
Returns
kSuccess if successful or returns an error code.