InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PMPageSize.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: sheridan
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 // Purpose:
24 //
25 //========================================================================================
26 
27 #ifndef __PageSize__
28 #define __PageSize__
29 
30 
31 #include "BaseType.h"
32 //#include "K2Assert.h"
33 #include "PMReal.h"
34 #include "PMRect.h"
35 #include "K2Pair.h"
36 #include <cmath>
37 
38 class IPMStream;
39 
41 {
42 public:
43  typedef base_type data_type; //K2Vector requirement
44 
45 
46  PMPageSize( PMReal width, PMReal height, K2Pair<PMReal, PMReal> scale)
47  : fWidth(width), fHeight(height), fWidthScale(scale.first), fHeightScale(scale.second), fEnumerationTag(0)
48  {}
49 
50  PMPageSize( PMReal width, PMReal height)
51  : fWidth(width), fHeight(height), fWidthScale(1.0), fHeightScale(1.0), fEnumerationTag(0)
52  {}
53 
54  PMPageSize( PMReal width, PMReal height, const PMPoint& square_inch)
55  : fWidth(width), fHeight(height), fWidthScale(72.0/square_inch.X()), fHeightScale(72.0/square_inch.Y()), fEnumerationTag(0)
56  {}
57 
58  explicit PMPageSize( const PMRect& r)
59  : fWidth(r.Width()), fHeight(r.Height()), fWidthScale(1.0), fHeightScale(1.0), fEnumerationTag(0)
60  {}
61 
62  explicit PMPageSize( uint32 tag)
63  : fWidth(0.), fHeight(0.), fWidthScale(1.0), fHeightScale(1.0), fEnumerationTag(tag)
64  {
65  ASSERT(fEnumerationTag > 0); //could just add 1 to the provided tag and skip the assert, but then I'd have to assert the add didn't wrap to zero
66  }
67 
68 
69 // explicit operator PMRect() const { return PMRect(0., 0., fWidth, fHeight);}
70 
71 
72 
73 
74  PMReal OutputWidth() const
75  {
76  return fWidth;
77  }
78 
79  PMReal OutputHeight() const
80  {
81  return fHeight;
82  }
83 
84  PMPoint OutputDimensions() const
85  {
86  return PMPoint( OutputWidth(), OutputHeight());
87  }
88 
89 
90 
91 
92  PMReal DesignWidth() const
93  {
94  return fWidth*fWidthScale;
95  }
96 
97  PMReal DesignHeight() const
98  {
99  return fHeight*fHeightScale;
100  }
101 
102  PMPoint DesignDimensions() const
103  {
104  return PMPoint( DesignWidth(), DesignHeight());
105  }
106 
107 
108 
109 
110  PMReal WidthScale() const
111  {
112  return fWidthScale;
113  }
114 
115  PMReal HeightScale() const
116  {
117  return fHeightScale;
118  }
119 
120 
121 
122  PMReal WidthPPI() const
123  {
124  return 72.0 / fWidthScale;
125  }
126 
127  PMReal HeightPPI() const
128  {
129  return 72.0 / fHeightScale;
130  }
131 
132 
133  bool16 operator==(const PMPageSize& other) const //careful PMReal fuzz at play
134  {
135  if( fEnumerationTag || other.fEnumerationTag)
136  return fEnumerationTag == other.fEnumerationTag;
137 
138  return
139  fWidth == other.fWidth
140  && fHeight == other.fHeight
141  && fWidthScale == other.fWidthScale
142  && fHeightScale == other.fHeightScale;
143  }
144 
145  bool16 operator!=(const PMPageSize& other) const //careful PMReal fuzz at play
146  {
147  return !(*this == other);
148  }
149 
150 
151 
152 
153  PMReal OutputShape() const
154  {
155  return ShapeMeasure_( fWidth, fHeight);
156  }
157 
158  bool16 OutputIsWide() const
159  {
160  return OutputShape() > 1.; //careful PMReal fuzz at play
161  }
162 
163  bool16 OutputIsTall() const
164  {
165  return OutputShape() < 1.; //careful PMReal fuzz at play
166  }
167 
168  bool16 OutputIsSquare() const
169  {
170  return OutputShape() == 1.; //careful PMReal fuzz at play
171  }
172 
173  bool16 OutputIsEmpty() const
174  {
175  return fWidth*fHeight == 0.; //careful PMReal fuzz at play
176  }
177 
178 
179  PMReal DesignShape() const
180  {
181  return ShapeMeasure_( fWidth*fWidthScale, fHeight*fHeightScale);
182  }
183 
184  bool16 DesignIsWide() const
185  {
186  return DesignShape() > 1.; //careful PMReal fuzz at play
187  }
188 
189  bool16 DesignIsTall() const
190  {
191  return DesignShape() <= 1.; //careful PMReal fuzz at play
192  }
193 
194  bool16 DesignIsSquare() const
195  {
196  return DesignShape() == 1.; //careful PMReal fuzz at play
197  }
198 
199  bool16 DesignIsEmpty() const
200  {
201  return fWidth*fWidthScale*fHeight*fHeightScale == 0.; //careful PMReal fuzz at play
202  }
203 
204 
205  void ReadWrite( IPMStream* iPMStream);
206 
207 
208 
209 
210 private:
211 
212  double ShapeMeasure_( PMReal w, PMReal h) const //hmm what about (0,0)? atan2 return 0.
213  {
214  return std::atan2( std::fabs(ToDouble(w)), std::fabs(ToDouble(h)))/std::atan(1.); //normalize [0..2] note shape is > 1 for landscape aspect ratios
215  }
216 
217  PMReal fWidth, fHeight, fWidthScale, fHeightScale;
218  uint32 fEnumerationTag;
219 };
220 
221 
222 
223 inline PMPageSize TransposedPageSize( const PMPageSize& ps)
224 {
225  return PMPageSize( ps.OutputHeight(), ps.OutputWidth(), K2Pair<PMReal,PMReal>(ps.HeightScale(), ps.WidthScale()));
226 }
227 
228 extern const PMPageSize kPMPageSizeCustom;
229 extern const PMPageSize kPMPageSizeDefine;
230 extern const PMPageSize kPMPageSizeMixed;
231 extern const PMPageSize kPMPageSizeEmpty;
232 extern const PMPageSize kPMPageSizeNeighbor;
233 extern const PMPageSize kPMPageSizeDefault;
234 
235 #endif