![]() | InDesign SDK 20.5 |
#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 | |
| IScript * | GetScript () const |
| IScript * | GetTargetScript () const |
| const ScriptID & | GetObjectType () const |
| void | CacheCurrentAttrs () |
| ErrorCode | AccessMultiplierAttribute (IScriptRequestData *data, const ScriptID &propID, const ClassID &attrClass, const PMReal &multiplier) |
| bool16 | IsFindChangeObject (const ScriptID &objectType) |
| IFontFamily * | QueryFontFamilyFromScript (IScriptRequestData *data, const ScriptID &propID, PMString fontStyle) |
| IFontFamily * | QueryFontFamilyFromModel (IScriptRequestData *data, const ClassID &fontClass, PMString fontStyle) |
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.| TextAttrScriptUtility::TextAttrScriptUtility | ( | IScript * | script, |
| const RequestContext & | context, | ||
| IScript * | target = nil | ||
| ) |
Construct a new TextAttrScriptUtility
| script | Pointer to script boss, see comments at top of file. is the target object that has text attributes you plan to get or set |
| ErrorCode TextAttrScriptUtility::AccessBoolAttribute | ( | IScriptRequestData * | data, |
| const ScriptID & | propID, | ||
| const ClassID & | attrClass | ||
| ) |
AccessBoolAttribute. Get/Set a boolean attribute.
| data | Pointer to IScriptRequestData. |
| propID | ScriptID of the property to be accessed. |
| attrClass | Boss must implement IID_ITEXTATTRBOOLEAN |
| ErrorCode TextAttrScriptUtility::AccessColor | ( | IScriptRequestData * | data, |
| const ScriptID & | propID, | ||
| const ClassID & | attrClass, | ||
| const bool16 | useTextColor = kTrue | ||
| ) |
AccessColor. Get/Set a color attribute.
| data | Pointer to IScriptRequestData. Accepts "Text Color", swatch object or en_Nothing on set, returns "Text Color" string or swatch object on get. |
| propID | ScriptID of the property to be accessed. |
| attrClass | Boss 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. |
| ErrorCode TextAttrScriptUtility::AccessDesignAxes | ( | IScriptRequestData * | data, |
| const ScriptID & | propID, | ||
| const ClassID & | fontClass, | ||
| const ClassID & | styleClass, | ||
| const ClassID & | strand = kCharAttrStrandBoss | ||
| ) |
AccessDesignAxes
| data | data Pointer to IScriptRequestData expected to contain design axes of variable font. |
| propID | ScriptID of the property to be accessed, should be p_DesignAxes. |
| fontClass | Boss must implement IID_ITEXTATTRUID |
| styleClass | Boss must implement IID_ITEXATTRUID |
| strand | One of kCharAttrStrandBoss or kParaAttrStrandBoss |
| ErrorCode TextAttrScriptUtility::AccessFont | ( | IScriptRequestData * | data, |
| const ScriptID & | propID, | ||
| const ClassID & | fontClass, | ||
| const ClassID & | styleClass, | ||
| const ClassID & | strand = kCharAttrStrandBoss, | ||
| bool16 | returnFontName = kFalse | ||
| ) |
AccessFont. Get/Set a font attribute.
| data | Pointer to IScriptRequestData. |
| propID | ScriptID of the property to be accessed. |
| fontClass | Boss must implement IID_ITEXTATTRUID |
| styleClass | Boss must implement IID_ITEXATTRUID |
| strand | One of kCharAttrStrandBoss or kParaAttrStrandBoss |
| returnFontName | If kTrue, display family name is returned, otherwise Script object for the font. |
| ErrorCode TextAttrScriptUtility::AccessFontStyle | ( | IScriptRequestData * | data, |
| const ScriptID & | propID, | ||
| const ClassID & | fontClass, | ||
| const ClassID & | styleClass, | ||
| const ClassID & | strand = kCharAttrStrandBoss | ||
| ) |
AccessFontStyle. Get/Set a font style attribute.
| data | Pointer to IScriptRequestData. |
| propID | ScriptID of the property to be accessed. |
| fontClass | Boss must implement IID_ITEXTATTRUID |
| styleClass | Boss must implement IID_ITEXATTRUID |
| strand | One of kCharAttrStrandBoss or kParaAttrStrandBoss |
| ErrorCode TextAttrScriptUtility::AccessInt16Attribute | ( | IScriptRequestData * | data, |
| const ScriptID & | propID, | ||
| const ClassID & | attrClass | ||
| ) |
AccessInt16Attribute. Get/Set a int16 attribute.
| data | Pointer to IScriptRequestData. |
| propID | ScriptID of the property to be accessed. |
| attrClass | Boss must implement IID_ITEXTATTRINT16 |
| ErrorCode TextAttrScriptUtility::AccessInt32Attribute | ( | IScriptRequestData * | data, |
| const ScriptID & | propID, | ||
| const ClassID & | attrClass | ||
| ) |
AccessInt32Attribute. Get/Set a int32 attribute.
| data | Pointer to IScriptRequestData. |
| propID | ScriptID of the property to be accessed. |
| attrClass | Boss must implement IID_ITEXTATTRINT32 |
| ErrorCode TextAttrScriptUtility::AccessLineTypeAttribute | ( | IScriptRequestData * | data, |
| const ScriptID & | propID, | ||
| const ClassID & | attrClass | ||
| ) |
AccessLineTypeAttribute. Get/Set a line type attribute.
| data | Pointer to IScriptRequestData. Calls IPathStrokerUtils::GetStrokeStyleForSetProperty() on set, IPathStrokeUtils::GetStrokeStyleForGetProperty() on get. |
| propID | ScriptID of the property to be accessed. |
| attrClass | Boss must implement IID_ITEXTATTRSTROKETYPE. |
| protected |
AccessMultiplierAttribute
| data | Pointer to IScriptRequestData. |
| propID | ScriptID of the property to be accessed. |
| attrClass | Boss must implement IID_ITEXTATTRREALNUMBER |
| multiplier | Returned values are multiplied by this value, set values are divided by this value. |
| ErrorCode TextAttrScriptUtility::AccessPercentageAttribute | ( | IScriptRequestData * | data, |
| const ScriptID & | propID, | ||
| const ClassID & | attrClass | ||
| ) |
AccessPercentageAttribute. Get/Set a percentage attribute. The implementation calls AccessMultiplierAttribute with a multiplier of 100.0.
| data | Pointer to IScriptRequestData. |
| propID | ScriptID of the property to be accessed. |
| attrClass | Boss must implement IID_ITEXTATTRREALNUMBER |
| ErrorCode TextAttrScriptUtility::AccessRealAttribute | ( | IScriptRequestData * | data, |
| const ScriptID & | propID, | ||
| const ClassID & | attrClass | ||
| ) |
AccessRealAttribute. Get/Set a real number attribute. The implementation calls AccessMultiplierAttribute with a multiplier of 1.0.
| data | Pointer to IScriptRequestData. |
| propID | ScriptID of the property to be accessed. |
| attrClass | Boss must implement IID_ITEXTATTRREALNUMBER |
| ErrorCode TextAttrScriptUtility::AccessUnitAttribute | ( | IScriptRequestData * | data, |
| const ScriptID & | propID, | ||
| const ClassID & | attrClass, | ||
| ScriptData::UnitType | unitType | ||
| ) |
AccessUnitAttribute. Get/Set a Unit attribute based on a PMReal.
| data | Pointer to IScriptRequestData. |
| propID | ScriptID of the property to be accessed. |
| attrClass | Boss must implement IID_ITEXTATTRREALNUMBER |
| unitType | Caller specifies script unit type |
| ErrorCode TextAttrScriptUtility::AddAttribute | ( | const IPMUnknown * | addAttr, |
| IDataBase * | targetDB = nil | ||
| ) |
Add Attribute.
| addAttr | Pointer to attribute boss. |
| targetDB | Pointer to IDataBase. Only used by FindChange objects. |
| ErrorCode TextAttrScriptUtility::AddAttributes | ( | const AddAttributeList & | addAttrList, |
| IDataBase * | targetDB = nil | ||
| ) |
AddAttributes.
| addAttrList | Reference to AttributeBossList |
| targetDB | Pointer to IDataBase. Only used by FindChange objects. |
| ErrorCode TextAttrScriptUtility::ApplyScriptCmd | ( | ) |
ApplyScriptCmd. Apply the attributes added and/or removed.
| 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 ClassID & | attrClass, |
| InterfacePtr< const IAttrReport > & | attrReport | ||
| ) |
GetAttributeReport
| attrClass | Boss must implement IID_IATTRREPORT |
| attrReport | Reference to InterfacePtr which will be reset with the boss of the requested class |
| inlineprotected |
GetObjectType
| inlineprotected |
GetScript
| inlineprotected |
GetTargetScript
| protected |
IsFindChangeObject
| objectType | to check. |
| ErrorCode TextAttrScriptUtility::IsNthDesignAxisHidden | ( | IScriptRequestData * | data, |
| IScript * | script, | ||
| const ClassID & | fontClass, | ||
| const ClassID & | styleClass | ||
| ) |
IsNthDesignAxisHidden
| data | Pointer to IScriptRequestData expected to contain index of design axis of variable font. |
| script | Pointer to script boss, see comments at top of file. |
| fontClass | Boss must implement IID_ITEXTATTRUID |
| styleClass | Boss must implement IID_ITEXTATTRFONT |
| protected |
QueryFontFamilyFromModel
| data | Pointer to IScriptRequestData. |
| fontClass | Boss must implement IID_ITEXTATTRUID |
| fontStyle | Ignored argument |
| protected |
QueryFontFamilyFromScript
| data | Pointer to IScriptRequestData expected to contain string type of the display family name. |
| propID | ScriptID of the property to be accessed, should be p_TextFont. |
| fontStyle | Desired style name of the font |
| ErrorCode TextAttrScriptUtility::RemoveAttribute | ( | const ClassID & | removeAttr | ) |
RemoveAttribute.
| removeAttr | The ClassID of the attribute to be removed. |
| ErrorCode TextAttrScriptUtility::RemoveAttributes | ( | const RemoveAttributeList & | removeAttrList | ) |
RemoveAttributes
| removeAttrList | Reference to AttributeBossList containing attributes to be removed. |
| ErrorCode TextAttrScriptUtility::SetNthDesignAxis | ( | IScriptRequestData * | data, |
| IScript * | script, | ||
| const ClassID & | fontClass, | ||
| const ClassID & | styleClass, | ||
| const ClassID & | strand = kCharAttrStrandBoss | ||
| ) |
AccessDesignAxes
| data | data Pointer to IScriptRequestData expected to contain index and value of design axis of variable font. |
| script | Pointer to script boss, see comments at top of file. |
| fontClass | Boss must implement IID_ITEXTATTRUID |
| styleClass | Boss must implement IID_ITEXATTRUID |
| strand | One of kCharAttrStrandBoss or kParaAttrStrandBoss |