00001 // $Id: oilcoord.cpp 1282 2006-06-09 09:46:49Z alex $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 00099 00100 #include "camtypes.h" 00101 00102 //#include "oilcoord.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00103 //#include "node.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00104 //#include "wrkcoord.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00105 //#include "rect.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00106 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00107 #include "paper.h" 00108 //#include "xmatrix.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00109 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00110 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00111 #include "chapter.h" 00112 //#include "view.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00113 00114 DECLARE_SOURCE("$Revision: 1282 $"); 00115 00116 00117 00118 00119 /********************************************************************************************* 00120 > OilCoord::OilCoord(MILLIPOINT xx, MILLIPOINT yy) 00121 00122 Author: Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> 00123 Created: 27th August 1993 00124 Inputs: Two INT32s (measured in millipoints). 00125 Outputs: - 00126 Returns: - 00127 Purpose: Constructs an OIL coordinate. 00128 Errors: - 00129 Scope: Public 00130 00131 **********************************************************************************************/ 00132 00133 OilCoord::OilCoord(MILLIPOINT xx, MILLIPOINT yy) : Coord(xx, yy) 00134 { 00135 } 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 /******************************************************************************************** 00146 00147 > WinCoord OilCoord::ToWin(View *pView) const; 00148 00149 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00150 Created: 5/8/93 00151 Inputs: The view we are converting to. 00152 Purpose: Converts an OilCoord to a WinCoord. 00153 00154 ********************************************************************************************/ 00155 00156 WinCoord OilCoord::ToWin(View *pView) const 00157 { 00158 // Note that we have to negate the y coord, because Windows starts with 0 at the top 00159 // and then positive coordinates in a downward direction, i.e. the opposite to 00160 // Camelot's coordinate systems. 00161 00162 // NB. More importantly, we add 1 to the y coord, because the flipping of the y axis 00163 // causes a misalignment in the pixel systems. This is because Camelot coords 00164 // specify the bottom left of the pixel, whereas GDI coords specify the top-left. 00165 // (See coord.doc for more details) 00166 00167 // return WinCoord(INT32(MPtoPixel(x, xPixelScale)), -INT32(MPtoPixel(y, yPixelScale) + 1)); 00168 00169 // New info: (Phil, 17/11/94) 00170 // The one pixel bodge is no longer required because the pixel model has been modified 00171 // so that pixel coordinates are in the centres of pixels, not on any edge. 00172 // This allows coordinate systems to be negated without any extra work. 00173 00174 // Get pixel size for this view 00175 FIXED16 PixelWidth, PixelHeight; 00176 pView->GetPixelSize(&PixelWidth, &PixelHeight); 00177 00178 // Do the conversion and return the results. 00179 return WinCoord(INT32(MPtoPixel(x, PixelWidth)), -INT32(MPtoPixel(y, PixelHeight) )); 00180 } 00181 00182 00183 /******************************************************************************************** 00184 00185 > WinCoord OilCoord::ToWin( const INT32 dpi ) const; 00186 00187 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00188 Created: 30/11/93 00189 Inputs: Transform Matrix. 00190 dpi the value of the destination dpi rather than assuming screen dpi 00191 Outputs: None 00192 Returns: None. 00193 Purpose: Same as above in that it converts an OilCoord to a WinCoord but instead of 00194 assuming screen dpi, as in using x/yPixelScale, it uses the specified dpi 00195 to work out the transformation. 00196 Errors: None. 00197 00198 ********************************************************************************************/ 00199 00200 //WinCoord OilCoord::ToWin( const INT32 dpi ) const 00201 //{ 00202 // See above ToWin routine for conversion comments 00203 // Work out our x and y pixel scaling factors for the specified destination dpi 00204 // FIXED16 PixScale = 72000.0/dpi; 00205 00206 // return WinCoord(INT32(MPtoPixel(x, PixScale)), -INT32(MPtoPixel(y, PixScale) )); 00207 //} 00208 00209 /******************************************************************************************** 00210 00211 > WinCoord OilCoord::ToWin( const double dpi ) const; 00212 00213 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00214 Created: 30/11/93 00215 Inputs: Transform Matrix. 00216 dpi the value of the destination dpi rather than assuming screen dpi 00217 Outputs: None 00218 Returns: None. 00219 Purpose: Same as above in that it converts an OilCoord to a WinCoord but instead of 00220 assuming screen dpi, as in using x/yPixelScale, it uses the specified dpi 00221 to work out the transformation. 00222 Different to above in that it takes a double dpi instead of a INT32 dpi. Now 00223 superceeds the above. Changed 12/12/95. 00224 Errors: None. 00225 00226 ********************************************************************************************/ 00227 00228 WinCoord OilCoord::ToWin( const double dpi ) const 00229 { 00230 // See above ToWin routine for conversion comments 00231 // Work out our x and y pixel scaling factors for the specified destination dpi 00232 FIXED16 PixScale = 72000.0/dpi; 00233 00234 return WinCoord(INT32(MPtoPixel(x, PixScale)), -INT32(MPtoPixel(y, PixScale) )); 00235 } 00236 00237 00238 00239 00240 /******************************************************************************************** 00241 00242 > WorkCoord OilCoord::ToWork(const WorkCoord& ScrollOffset) const 00243 00244 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00245 Created: 5/8/93 00246 Inputs: Scroll offset. 00247 Outputs: None 00248 Returns: None. 00249 Purpose: Converts an OilCoord to a WorkCoord. 00250 Errors: None. 00251 00252 ********************************************************************************************/ 00253 00254 WorkCoord OilCoord::ToWork(const WorkCoord& ScrollOffset) const 00255 { 00256 // Add the scroll offsets to get workarea values... 00257 return WorkCoord(ScrollOffset.x + x, ScrollOffset.y + y); 00258 } 00259 00260 00261 00262 00263 /******************************************************************************************** 00264 00265 > void OilCoord::ToWork(const WorkCoord& scrollOffset, WorkCoord* result ) const 00266 00267 Author: Will_Cowling (Xara Group Ltd) <camelotdev@xara.com> 00268 Created: 5/8/93 00269 Inputs: Scroll offset. 00270 Outputs: None 00271 Returns: None. 00272 Purpose: Converts an OilCoord to a WorkCoord. 00273 Errors: None. 00274 00275 ********************************************************************************************/ 00276 /* 00277 Technical notes: 00278 00279 ********************************************************************************************/ 00280 00281 void OilCoord::ToWork(const WorkCoord& scrollOffset, WorkCoord* result ) const 00282 { 00283 // Implementation... 00284 // Then add the scroll offsets to get workarea values... 00285 result->x = scrollOffset.x + x; 00286 result->y = scrollOffset.y + y; 00287 } 00288 00289 00290 00291 00292 /******************************************************************************************** 00293 00294 > DocCoord OilCoord::ToDoc(const Spread* pSpread, View *pView) const 00295 00296 Author: Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com> 00297 Created: 22/12/93 00298 Inputs: pSpread - The spread that we know that the oil coord is in 00299 View - the view to use when converting. 00300 Returns: This coordinate as measured in DocCoords 00301 Purpose: Convert an OilCoord to a DocCoord 00302 00303 ********************************************************************************************/ 00304 00305 DocCoord OilCoord::ToDoc(const Spread* pSpread, View* pView) const 00306 { 00307 DocCoord Return; 00308 WorkCoord Point((XLONG)(this->x), (XLONG)(this->y)); 00309 00310 // First, convert the OilCoord into a LogicalCoord... 00311 FIXED16 ViewScale = pView->GetViewScale(); 00312 WorkCoord ScrollOffset = pView->GetScrollOffsets(); 00313 00314 Point.x = MakeXLong( double(Point.x + ScrollOffset.x) / ViewScale.MakeDouble()); 00315 Point.y = MakeXLong( double(Point.y + ScrollOffset.y) / ViewScale.MakeDouble()); 00316 00317 // Find the parent chapter 00318 Chapter* pChapter = (Chapter*) pSpread->FindParent(); 00319 ENSURE( pChapter != NULL, "Spread had no parent" ); 00320 ENSURE( pChapter->IsKindOf(CC_RUNTIME_CLASS(Chapter)), "Chapter is not a chapter" ); 00321 00322 // Find the depth of the chapter 00323 XLONG ChapDepth = pChapter->GetChapterDepth(); 00324 00325 // Find the chapters position 00326 DocCoord ChapterPos; 00327 ChapterPos.x = pChapter->GetPasteboardRect(TRUE, pView).lo.x; 00328 ChapterPos.y = pChapter->GetPasteboardRect(TRUE, pView).hi.y; 00329 00330 // Build the return value up 00331 Return.x = Point.x + ChapterPos.x; 00332 Return.y = Point.y + MakeXLong(ChapterPos.y) + ChapDepth; 00333 00334 return (Return); 00335 00336 }