InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
SnpTextAttrHelper.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Adobe Developer Technologies
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //========================================================================================
23 
24 #ifndef __SnpTextAttrHelper_H_DEFINED__
25 #define __SnpTextAttrHelper_H_DEFINED__
26 
27 class IAttrReport;
28 
29 namespace SnpTextAttrHelper {
30 
31 // TODO Align with coding conventions
32 
44 template <class TextAttrType, class _Val_Type>
45 ErrorCode GetTextAttribute(const InDesign::TextRange& textRange,
46  const ClassID& attrClassID,
47  _Val_Type& value)
48 {
49  // Assume failure.
50  ErrorCode status = kFailure;
51  do
52  {
53  // Check if the text range is valid.
54  if (textRange.IsValid() == kFalse)
55  {
56  SNIPLOG("textRange is invalid - you must have some text selected first.");
57  break;
58  }
59 
60  // Query the text model and get the range data,
61  InterfacePtr<ITextModel> textModel(textRange.QueryModel());
62  RangeData rangeData = textRange.GetRange();
63 
64  // Query the compose scanner to access text attributes
65  InterfacePtr<IComposeScanner> composeScanner(textModel, UseDefaultIID());
66  if (composeScanner == nil)
67  {
68  ASSERT(composeScanner); break;
69  }
70 
71  // Query attribute report interface
72  int32 attrLen = 0;
73  InterfacePtr<const IAttrReport> attrReport(composeScanner->QueryAttributeAt(rangeData, attrClassID, &attrLen));
74  if (attrReport == nil)
75  {
76  SNIPLOG("Could not find text attribute with Class ID 0x%X on the selected text!", attrClassID.Get());
77  break;
78  }
79 
80  // Query the attribute interface
81  InterfacePtr<TextAttrType> attr(attrReport, TextAttrType::kDefaultIID);
82  if (attr == nil)
83  {
84  SNIPLOG("attr is nil! (Class ID 0x%X)", attrClassID.Get());
85  break;
86  }
87 
88  // Get the attribute value.
89  const _Val_Type tempValue = attr->Get();
90  value = tempValue;
91  status = kSuccess;
92  } while (false);
93 
94  return status;
95 }
96 
106 ErrorCode GetTextFontStyleAttribute(const InDesign::TextRange& textRange,
107  const ClassID& attrClassID,
108  PMString& fontName);
109 
120 ErrorCode GetTextBool16Attribute(const InDesign::TextRange& textRange,
121  const ClassID& attrClassID,
122  bool16& value);
123 
133 template <class TextAttrType, class _Val_Type>
134 IAttrReport* CreateTextAttribute(const ClassID& attrClassID,
135  const _Val_Type& value)
136 {
137  IAttrReport* attrReport = nil;
138  do {
139  // create the text attribute boss
140  InterfacePtr<TextAttrType> attr(::CreateObject2<TextAttrType>(attrClassID));
141  if (attr == nil)
142  {
143  ASSERT_FAIL("attr is nil!");
144  break;
145  }
146  // set the attribute value
147  const _Val_Type tempValue = value;
148  attr->Set(tempValue);
149 
150  InterfacePtr<IAttrReport> localAttrReport(attr, UseDefaultIID());
151  attrReport = localAttrReport.forget();
152  } while (false);
153  ASSERT(attrReport);
154 
155  return attrReport;
156 }
157 
158 
167 IAttrReport* CreateTextFontStyleAttribute(const ClassID& attrClassID,
168  const PMString& fontName);
169 
178 IAttrReport* CreateTextBool16Attribute(const ClassID& attrClassID,
179  const bool16& fontName);
180 
189 ErrorCode SetTextBool16Attribute(const InDesign::TextRange& textRange,
190  const ClassID& attrClassID,
191  const bool16 value,
192  const ClassID& whichStrand = kCharAttrStrandBoss);
193 
205 ErrorCode SetTextInt16Attribute(const InDesign::TextRange& textRange,
206  const ClassID& attrClassID,
207  const int16 value,
208  const ClassID& whichStrand = kCharAttrStrandBoss);
209 
210 
211 }; // end namespace SnpTextAttrHelper
212 
213 #endif //#define __SnpTextAttrHelper_H_DEFINED__
214 
215 //End, SnpTextAttrHelper.h