00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #pragma once
00020 #include "AIBasicTypes.h"
00021 #include "AITypes.h"
00022 #include "AIRealMath.h"
00023 #include "AITransformArt.h"
00024
00025 namespace ai
00026 {
00027 namespace DocumentUtils
00028 {
00037 AIReal GetDocumentScale();
00038
00042 AIRealMatrix GetTransFormMatrixForDocumentScale();
00043
00049 AIRealMatrix GetTransformMatrixForDocumentScaleFromReference( const AIRealPoint& referencePoint);
00050
00054 AIRealMatrix GetTransFormMatrixForScaleFactor(const AIReal& scaleFactor );
00055
00061 AIRealMatrix GetTransformMatrixForScaleFactorFromReference(const AIReal& scaleFactor, const AIRealPoint& referencePoint);
00062
00068 template <typename Rect>
00069 void ApplyScaleToRect(const Rect& inRect, Rect& outRect, const AIReal scale)
00070 {
00071 outRect.left = inRect.left * static_cast<decltype(inRect.left)>(scale);
00072 outRect.top = inRect.top * static_cast<decltype(inRect.top)>(scale);
00073 outRect.right = inRect.right * static_cast<decltype(inRect.right)>(scale);
00074 outRect.bottom = inRect.bottom * static_cast<decltype(inRect.bottom)>(scale);
00075 }
00076
00082 template <typename Rect>
00083 void ApplyDocumentScaleToRect( const Rect& inRect, Rect& outRect)
00084 {
00085 AIReal docScale = GetDocumentScale();
00086 ApplyScaleToRect(inRect, outRect, docScale);
00087 }
00088
00093 template <typename Point>
00094 void ApplyDocumentScaleToPoint(const Point& inPoint, Point& outPoint)
00095 {
00096 AIReal docScale = GetDocumentScale();
00097 outPoint.h = inPoint.h * static_cast<decltype(inPoint.h)>(docScale);
00098 outPoint.v = inPoint.v * static_cast<decltype(inPoint.v)>(docScale);
00099
00100 }
00101
00106 void ApplyDocumentScaleToAIReal( const AIReal& inReal, AIReal& outReal);
00107
00112 template <typename Rect>
00113 void DropDocumentScaleFromRect( const Rect& inRect, Rect& outRect)
00114 {
00115 AIReal docScale = GetDocumentScale();
00116 outRect.left = inRect.left / static_cast<decltype(inRect.left)>(docScale);
00117 outRect.top = inRect.top / static_cast<decltype(inRect.top)>(docScale);
00118 outRect.right = inRect.right / static_cast<decltype(inRect.right)>(docScale);
00119 outRect.bottom = inRect.bottom / static_cast<decltype(inRect.bottom)>(docScale);
00120 }
00121
00126 template <typename Point>
00127 void DropDocumentScaleFromPoint(const Point& inPoint, Point& outPoint)
00128 {
00129 AIReal docScale = GetDocumentScale();
00130 outPoint.h = inPoint.h / static_cast<decltype(inPoint.h)>(docScale);
00131 outPoint.v = inPoint.v / static_cast<decltype(inPoint.v)>(docScale);
00132 }
00133
00138 void DropDocumentScaleFromAIReal( const AIReal& inReal, AIReal& outReal);
00139
00140 class ArtScaler
00141 {
00142 public:
00143 ArtScaler(AIReal scale, ai::int32 transformOptions)
00144 : mScaleFactor{ scale },
00145 mTransformOptions{ transformOptions }
00146 {}
00147
00148 AIErr ScaleArt(AIArtHandle art);
00149
00150 AIErr DownScaleArt(AIArtHandle art);
00151
00152 bool IsScaleFactorOne()
00153 {
00154 return mScaleFactor == kAIRealOne;
00155 }
00156
00157 private:
00158 AIReal mScaleFactor{ kAIRealOne };
00159 ai::int32 mTransformOptions{ 0 };
00160 AIRealMatrix GetScaledXformMatrix(AIArtHandle art, AIReal scale);
00161 };
00162 }
00163 }