home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / SLMaping.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  23.8 KB  |  852 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                SLMaping.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWMAPING_H
  13. #include "SLMaping.h"
  14. #endif
  15.  
  16. #ifndef PRGDEV_H
  17. #include "PRGDev.h"
  18. #endif
  19.  
  20. #ifndef SLREGION_H
  21. #include "SLRegion.h"
  22. #endif
  23.  
  24. #ifndef FWGRUTIL_H
  25. #include "FWGrUtil.h"
  26. #endif
  27.  
  28. #ifndef FWODGEOM_H
  29. #include "FWODGeom.h"
  30. #endif
  31.  
  32. #ifndef FWSOMENV_H
  33. #include "FWSOMEnv.h"
  34. #endif
  35.  
  36. // ----- OpenDoc Includes -----
  37.  
  38. #ifndef SOM_ODTransform_xh
  39. #include <Trnsform.xh>
  40. #endif
  41.  
  42. #ifndef SOM_ODShape_xh
  43. #include <Shape.xh>
  44. #endif
  45.  
  46. #ifdef FW_BUILD_MAC
  47. #pragma segment FW_Graphics
  48. #endif
  49.  
  50. //========================================================================================
  51. //    Local prototypes
  52. //========================================================================================
  53.  
  54. static void                ClearCache(FW_SMapping& mapping, Environment* ev);
  55.  
  56. static void                CheckCache(
  57.                             const FW_SMapping& mapping,
  58.                             Environment* ev,
  59.                             FW_HGDevice device,
  60.                             ODTransform* transform);
  61.  
  62. static void                CalcCache(
  63.                             FW_SMapping& mapping,
  64.                             Environment* ev,
  65.                             FW_HGDevice device,
  66.                             ODTransform* transform);
  67.  
  68. static void                CalcOriginOffset(
  69.                             FW_SMapping& mapping,
  70.                             Environment* ev,
  71.                             FW_HGDevice device);
  72.  
  73. //========================================================================================
  74. //    Mapping functions
  75. //========================================================================================
  76.  
  77. //----------------------------------------------------------------------------------------
  78. //    FW_PrivMapping_Init
  79. //----------------------------------------------------------------------------------------
  80.  
  81. void SL_API FW_PrivMapping_Init(FW_SMapping& mapping, FW_EMappingModes mappingMode)
  82. {
  83.     // No try block necessary - Do not throw
  84.     mapping.fMappingMode                =     mappingMode;
  85.     mapping.fRecentDevice                =    NULL;
  86.     mapping.fRecentODTransform            =    NULL;
  87.     mapping.fLogicalToContentTransform    =    NULL;
  88.     mapping.fContentToDeviceTransform    =    NULL;
  89.     mapping.fLogicalToDeviceTransform    =    NULL;
  90.     mapping.fHaveTransforms                =    FALSE;
  91.  
  92.     mapping.fDeviceOrg.x                 = 
  93.     mapping.fDeviceOrg.y                 = 
  94.     mapping.fLogicalOrg.x                 = 
  95.     mapping.fLogicalOrg.y                 =    FW_kFixed0;
  96.  
  97.     mapping.fLogicalExtent.x             =
  98.     mapping.fLogicalExtent.y             =
  99.     mapping.fDeviceExtent.x             =
  100.     mapping.fDeviceExtent.y             =    FW_kFixedPos1;
  101. }
  102.  
  103. //----------------------------------------------------------------------------------------
  104. //    FW_PrivMapping_InitFromCopy
  105. //----------------------------------------------------------------------------------------
  106.  
  107. void SL_API FW_PrivMapping_InitFromCopy(FW_SMapping& mapping, const FW_SMapping& mapping2)
  108. {
  109.     // No try block necessary - Do not throw
  110.     mapping.fMappingMode                =     mapping2.fMappingMode;
  111.     mapping.fRecentDevice                =    NULL;
  112.     mapping.fRecentODTransform            =    NULL;
  113.     mapping.fLogicalToContentTransform    =    NULL;
  114.     mapping.fContentToDeviceTransform    =    NULL;
  115.     mapping.fLogicalToDeviceTransform    =    NULL;
  116.     mapping.fHaveTransforms                =    FALSE;
  117.  
  118.     mapping.fDeviceOrg                     =    mapping2.fDeviceOrg;
  119.     mapping.fLogicalOrg                 =     mapping2.fLogicalOrg;
  120.  
  121.     mapping.fLogicalExtent                 =    mapping2.fLogicalExtent;
  122.     mapping.fDeviceExtent                 =    mapping2.fDeviceExtent;
  123. }
  124.  
  125. //----------------------------------------------------------------------------------------
  126. //    FW_PrivMapping_Term
  127. //----------------------------------------------------------------------------------------
  128.  
  129. void SL_API FW_PrivMapping_Term(FW_SMapping& mapping, Environment* ev)
  130. {
  131.     // No try block necessary - Do not throw
  132.     ClearCache(mapping, ev);
  133. }
  134.  
  135. //----------------------------------------------------------------------------------------
  136. //    FW_PrivMapping_Reset
  137. //----------------------------------------------------------------------------------------
  138.  
  139. void SL_API FW_PrivMapping_Reset(FW_SMapping& mapping, Environment* ev)
  140. {
  141.     // No try block necessary - Do not throw
  142.     ClearCache(mapping, ev);
  143.     
  144.     mapping.fMappingMode = FW_kPoint;
  145.  
  146.     mapping.fLogicalExtent.x =
  147.     mapping.fLogicalExtent.y =
  148.     mapping.fDeviceExtent.x =
  149.     mapping.fDeviceExtent.y = FW_kFixedPos1;
  150.  
  151.     mapping.fDeviceOrg = FW_kZeroPoint;
  152.     mapping.fLogicalOrg = FW_kZeroPoint;
  153. }
  154.  
  155. //----------------------------------------------------------------------------------------
  156. //    FW_PrivMapping_SetMode
  157. //----------------------------------------------------------------------------------------
  158.  
  159. void SL_API FW_PrivMapping_SetMode(FW_SMapping& mapping, Environment* ev, FW_EMappingModes newMappingMode)
  160. {
  161.     // No try block necessary - Do not throw
  162.     mapping.fMappingMode = newMappingMode;
  163.     
  164.     if (mapping.fMappingMode == FW_kCustomConstrained)
  165.         FW_PrivMapping_SetExtents(mapping, ev, mapping.fLogicalExtent, mapping.fDeviceExtent);    // already calls ClearCache
  166.     else
  167.         ClearCache(mapping, ev);
  168. }
  169.  
  170. //----------------------------------------------------------------------------------------
  171. //    FW_PrivMapping_SetExtents
  172. //----------------------------------------------------------------------------------------
  173.  
  174. void SL_API FW_PrivMapping_SetExtents(
  175.                                 FW_SMapping& mapping,
  176.                                 Environment* ev,
  177.                                 const FW_SPoint& logicalExtent,
  178.                                 const FW_SPoint& deviceExtent)
  179. {
  180.     // No try block necessary - Do not throw
  181.     mapping.fLogicalExtent = logicalExtent;
  182.     mapping.fDeviceExtent = deviceExtent;
  183.     ClearCache(mapping, ev);
  184. }
  185.  
  186. //----------------------------------------------------------------------------------------
  187. //    FW_PrivMapping_SetDeviceOrigin
  188. //----------------------------------------------------------------------------------------
  189.  
  190. void SL_API FW_PrivMapping_SetDeviceOrigin(FW_SMapping& mapping, Environment* ev, FW_Fixed x, FW_Fixed y)
  191. {
  192.     // No try block necessary - Do not throw
  193.     mapping.fDeviceOrg.x = x;
  194.     mapping.fDeviceOrg.y = y;
  195.     ClearCache(mapping, ev);
  196. }
  197.  
  198. //----------------------------------------------------------------------------------------
  199. //    FW_PrivMapping_SetLogicalOrigin
  200. //----------------------------------------------------------------------------------------
  201.  
  202. void SL_API FW_PrivMapping_SetLogicalOrigin(FW_SMapping& mapping, Environment* ev, FW_Fixed x, FW_Fixed y)
  203. {
  204.     // No try block necessary - Do not throw
  205.     mapping.fLogicalOrg.x = x;
  206.     mapping.fLogicalOrg.y = y;
  207.     ClearCache(mapping, ev);
  208. }
  209.  
  210. //----------------------------------------------------------------------------------------
  211. //    FW_PrivMapping_GetOriginOffset
  212. //----------------------------------------------------------------------------------------
  213.  
  214. void SL_API FW_PrivMapping_GetOriginOffset(
  215.                                 const FW_SMapping& mapping,
  216.                                 Environment* ev,
  217.                                 FW_PlatformPoint& offset,
  218.                                 FW_HGDevice device,
  219.                                 ODTransform* transform)
  220. {
  221.     // No try block necessary - Do not throw
  222.     CheckCache(mapping, ev, device, transform);
  223.     offset = mapping.fOriginOffset;
  224. }
  225.  
  226. //========================================================================================
  227. //    Local helpers
  228. //========================================================================================
  229.  
  230. //----------------------------------------------------------------------------------------
  231. //    ClearCache
  232. //----------------------------------------------------------------------------------------
  233.  
  234. static void ClearCache(FW_SMapping& mapping, Environment* ev)
  235. {
  236.     // Will not throw
  237.     FW_SOM_TRY
  238.     {
  239.         if (mapping.fRecentDevice != NULL)
  240.         {
  241.             mapping.fRecentDevice->Release();
  242.             mapping.fRecentDevice = NULL;
  243.         }
  244.     
  245.         if (mapping.fRecentODTransform != NULL)
  246.         {
  247.             mapping.fRecentODTransform->Release(ev);
  248.             mapping.fRecentODTransform = NULL;
  249.         }
  250.     
  251.         if (mapping.fLogicalToContentTransform != NULL)
  252.         {
  253.             mapping.fLogicalToContentTransform->Release(ev);
  254.             mapping.fLogicalToContentTransform = NULL;
  255.         }
  256.     
  257.         if (mapping.fContentToDeviceTransform != NULL)
  258.         {
  259.             mapping.fContentToDeviceTransform->Release(ev);
  260.             mapping.fContentToDeviceTransform = NULL;
  261.         }
  262.     
  263.         if (mapping.fLogicalToDeviceTransform != NULL)
  264.         {
  265.             mapping.fLogicalToDeviceTransform->Release(ev);
  266.             mapping.fLogicalToDeviceTransform = NULL;
  267.         }
  268.         
  269.         mapping.fHaveTransforms = FALSE;
  270.     }
  271.     FW_SOM_CATCH
  272. }
  273.  
  274. //----------------------------------------------------------------------------------------
  275. //    CheckCache
  276. //----------------------------------------------------------------------------------------
  277.  
  278. static void CheckCache(const FW_SMapping& mapping,
  279.                         Environment* ev,
  280.                         FW_HGDevice device,
  281.                         ODTransform* transform)
  282. {
  283.     // No try block necessary - Do not throw
  284.     if (!mapping.fHaveTransforms || device != mapping.fRecentDevice || transform != mapping.fRecentODTransform)
  285.         CalcCache((FW_SMapping&)mapping, ev, device, transform);
  286.  
  287.     FW_ASSERT(mapping.fHaveTransforms);
  288.     FW_ASSERT(mapping.fLogicalToContentTransform != NULL);
  289.     FW_ASSERT(mapping.fContentToDeviceTransform != NULL);
  290.     FW_ASSERT(mapping.fLogicalToDeviceTransform != NULL);
  291. }
  292.  
  293. //----------------------------------------------------------------------------------------
  294. //    CalcCache
  295. //----------------------------------------------------------------------------------------
  296.  
  297. static void CalcCache(FW_SMapping& mapping,
  298.                     Environment* ev,
  299.                     FW_HGDevice device,
  300.                     ODTransform* transform)
  301. {
  302. // #define LOG_TRANSFORMS
  303.  
  304.     FW_SOM_TRY
  305.     {
  306.         ClearCache(mapping, ev);
  307.     
  308.         mapping.fRecentDevice = device;
  309.         if(mapping.fRecentDevice != NULL)
  310.         {
  311.             mapping.fRecentDevice->Acquire();
  312.         }
  313.             
  314.         mapping.fRecentODTransform = transform;
  315.         if(mapping.fRecentODTransform != NULL) 
  316.         {
  317.     #ifdef FW_BUILD_WIN
  318.             mapping.fRecentODTransform->IncrementRefCount(ev);
  319.     #endif
  320.     #ifdef FW_BUILD_MAC
  321.             mapping.fRecentODTransform->Acquire(ev);
  322.     #endif
  323.         }
  324.     
  325.         ODCanvas* canvas = device != NULL ? device->GetODCanvas() : NULL;
  326.         
  327.         FW_CPoint resScreen;
  328.     
  329.     #ifdef FW_BUILD_WIN
  330.         HDC hDC = ::GetDC(NULL);
  331.     
  332.         resScreen.x    = FW_IntToFixed(::GetDeviceCaps(hDC, LOGPIXELSX));
  333.         resScreen.y    = FW_IntToFixed(::GetDeviceCaps(hDC, LOGPIXELSY));
  334.     
  335.         ::ReleaseDC(NULL, hDC);
  336.         
  337.         BOOL bWinIsPrinting = canvas != NULL ? canvas->HasPlatformPrintJob(ev, kODWindows) : FALSE;
  338.     #endif
  339.     #ifdef FW_BUILD_MAC
  340.         resScreen.Set(FW_kFixed72, FW_kFixed72);
  341.     #endif
  342.     
  343.         FW_CPoint resDevice = device == NULL ? resScreen : device->GetResolution();
  344.             
  345.         FW_CPoint ptLogicalToContentOffset(-mapping.fLogicalOrg.x, -mapping.fLogicalOrg.y);
  346.         FW_CPoint ptLogicalToContentScaling;
  347.         FW_CPoint resScale;
  348.     
  349.         switch (mapping.fMappingMode)
  350.         {
  351.             case FW_kCentimeter:
  352.                 ptLogicalToContentScaling.x = FW_DoubleToFixed(28.346456691);
  353.                 ptLogicalToContentScaling.y = FW_DoubleToFixed(28.346456691);
  354.                 break;
  355.     
  356.             case FW_kInch:
  357.                 ptLogicalToContentScaling.x = FW_kFixed72;
  358.                 ptLogicalToContentScaling.y = FW_kFixed72;
  359.                 break;
  360.     
  361.             case FW_kPoint:    
  362.                 //    On the Mac:
  363.                 //        The screen is always assumed to be 72dpi, even though actual
  364.                 //        resolution may vary (this is the tradition!)
  365.                 //    On Windows:
  366.                 //        OpenDoc/Win emulates 72dpi
  367.                 ptLogicalToContentScaling.x = FW_kFixedPos1;
  368.                 ptLogicalToContentScaling.y = FW_kFixedPos1;
  369.                 break;
  370.     
  371.             case FW_kDevice:
  372.     #ifdef FW_BUILD_MAC
  373.                 ptLogicalToContentScaling.x = FW_kFixedPos1;
  374.                 ptLogicalToContentScaling.y = FW_kFixedPos1;
  375.     #endif
  376.     #ifdef FW_BUILD_WIN
  377.                 if (bWinIsPrinting)
  378.                 {
  379.                     // For printing, preserve the visual image size
  380.                     ptLogicalToContentScaling.x = FW_kFixed72 / resScreen.x;
  381.                     ptLogicalToContentScaling.y = FW_kFixed72 / resScreen.y;
  382.                 }
  383.                 else
  384.                 {
  385.                     // Counter-act OpenDoc's 72 dpi emulation
  386.                     ptLogicalToContentScaling.x = FW_kFixed72 / resDevice.x;
  387.                     ptLogicalToContentScaling.y = FW_kFixed72 / resDevice.y;
  388.                 }
  389.     #endif
  390.                 break;
  391.     
  392.             case FW_kCustomConstrained:
  393.                 {
  394.                     FW_Fixed oneUnitx = mapping.fDeviceExtent.x / mapping.fLogicalExtent.x / resDevice.x;
  395.                     FW_Fixed oneUnity = mapping.fDeviceExtent.y / mapping.fLogicalExtent.y / resDevice.y;
  396.                     if (oneUnitx < oneUnity)
  397.                         mapping.fDeviceExtent.y = oneUnitx * resDevice.y * mapping.fLogicalExtent.y;
  398.                     else if (oneUnitx > oneUnity)
  399.                         mapping.fDeviceExtent.x = oneUnity * resDevice.x * mapping.fLogicalExtent.x;
  400.                 }
  401.                 // continue                
  402.             case FW_kCustomUnconstrained:
  403.                 resScale.x = FW_kFixed72 / resDevice.x;
  404.                 resScale.y = FW_kFixed72 / resDevice.y;
  405.     
  406.                 ptLogicalToContentScaling.x =
  407.                     FW_WideMultiply(resScale.x, mapping.fDeviceExtent.x) / mapping.fLogicalExtent.x;
  408.                     
  409.                 ptLogicalToContentScaling.y =
  410.                     FW_WideMultiply(resScale.y, mapping.fDeviceExtent.y) / mapping.fLogicalExtent.y;
  411.     
  412.                 ptLogicalToContentOffset.x  = 
  413.                     FW_WideMultiply(mapping.fDeviceOrg.x, FW_kFixed72) / resDevice.x - mapping.fLogicalOrg.x * ptLogicalToContentScaling.x;
  414.     
  415.                 ptLogicalToContentOffset.y  =
  416.                     FW_WideMultiply(mapping.fDeviceOrg.y, FW_kFixed72) / resDevice.y - mapping.fLogicalOrg.y * ptLogicalToContentScaling.y;
  417.     
  418.                 break;
  419.         }
  420.     
  421.         // ----- Logical to content transform
  422.         mapping.fLogicalToContentTransform = ::FW_NewODTransform(ev, ptLogicalToContentOffset, ptLogicalToContentScaling);
  423.     
  424.         // ----- Content to device transform
  425.         if(transform != NULL)
  426.         {
  427.     #ifdef LOG_TRANSFORMS
  428.             FW_LogTransform(ev, "OD Content        ", transform);
  429.     #endif
  430.             mapping.fContentToDeviceTransform = ::FW_NewODTransform(ev, transform);
  431.         }
  432.         else
  433.         {
  434.             FW_CPoint scaling;
  435.     #ifdef FW_BUILD_WIN
  436.             if (bWinIsPrinting && mapping.fMappingMode == FW_kDevice)
  437.             {
  438.                 // Preserve visual image size
  439.                 scaling.x = resScreen.x / FW_kFixed72;
  440.                 scaling.y = resScreen.y / FW_kFixed72;
  441.             }
  442.             else
  443.     #endif
  444.             {
  445.                 scaling.x = resDevice.x / FW_kFixed72;
  446.                 scaling.y = resDevice.y / FW_kFixed72;
  447.             }
  448.     
  449.             mapping.fContentToDeviceTransform = ::FW_NewODTransform(ev);
  450.             mapping.fContentToDeviceTransform->ScaleBy(ev, (ODPoint*) &scaling);        
  451.         }
  452.     
  453.         // ------ Logical to device transform -----
  454.         mapping.fLogicalToDeviceTransform = ::FW_NewODTransform(ev, mapping.fLogicalToContentTransform);
  455.         mapping.fLogicalToDeviceTransform->PostCompose(ev, mapping.fContentToDeviceTransform);
  456.     
  457.         // ----- Adjust the origin
  458.         CalcOriginOffset(mapping, ev, device);
  459.     
  460.     #ifdef LOG_TRANSFORMS
  461.         FW_LogTransform(ev, "Logical -> Content", mapping.fLogicalToContentTransform);
  462.         FW_LogTransform(ev, "Content -> Device ", mapping.fContentToDeviceTransform);
  463.         FW_LogTransform(ev, "Logical -> Device ", mapping.fLogicalToDeviceTransform);
  464.     #endif
  465.     
  466.         mapping.fHaveTransforms = TRUE;
  467.     }
  468.     FW_SOM_CATCH
  469. }
  470.  
  471. //----------------------------------------------------------------------------------------
  472. //    CalcOriginOffset
  473. //----------------------------------------------------------------------------------------
  474.  
  475. static void CalcOriginOffset(FW_SMapping& mapping,
  476.                             Environment* ev,
  477.                             FW_HGDevice device)
  478. {
  479.     FW_SOM_TRY
  480.     {
  481.         ODCanvas* canvas = device != NULL ? device->GetODCanvas() : NULL;
  482.         FW_Boolean isPrinting = canvas != NULL && 
  483.     #ifdef FW_BUILD_WIN
  484.             (canvas->HasPlatformPrintJob(ev, kODWindows));
  485.     #endif
  486.     #ifdef FW_BUILD_MAC
  487.             (canvas->HasPlatformPrintJob(ev, kODQuickDrawGX) || canvas->HasPlatformPrintJob(ev, kODQuickDraw));
  488.     #endif
  489.     
  490.         FW_CPoint offset;
  491.         mapping.fLogicalToDeviceTransform->GetOffset(ev, offset);
  492.         if ((offset.x != FW_kFixed0 || offset.y != FW_kFixed0) && !isPrinting)
  493.         {
  494.             FW_SetXY(mapping.fOriginOffset, FW_FixedToInt(offset.x) % 8, FW_FixedToInt(offset.y) % 8);
  495.             offset.x = FW_IntToFixed(-FW_PointX(mapping.fOriginOffset));
  496.             offset.y = FW_IntToFixed(-FW_PointY(mapping.fOriginOffset));
  497.             mapping.fLogicalToDeviceTransform->MoveBy(ev, offset);
  498.         }
  499.         else
  500.         {
  501.             FW_SetXY(mapping.fOriginOffset, 0, 0);
  502.         }
  503.     }
  504.     FW_SOM_CATCH
  505. }
  506.  
  507. //----------------------------------------------------------------------------------------
  508. // ----- Logical ---> Content
  509. //----------------------------------------------------------------------------------------
  510.  
  511. void SL_API FW_PrivMapping_LogicalToContentPoint(
  512.                                 const FW_SMapping& mapping,
  513.                                 Environment* ev,
  514.                                 const FW_SPoint& ptFrom,
  515.                                 FW_SPoint& ptTo,
  516.                                 FW_HGDevice device,
  517.                                 ODTransform* transform)
  518. {
  519.     FW_SOM_TRY
  520.     {
  521.         CheckCache(mapping, ev, device, transform);
  522.         ptTo = FW_TransformCopy(ev, ptFrom, mapping.fLogicalToContentTransform);
  523.     }
  524.     FW_SOM_CATCH
  525. }
  526.  
  527. void SL_API FW_PrivMapping_LogicalToContentRect(
  528.                                 const FW_SMapping& mapping,
  529.                                 Environment* ev,
  530.                                 const FW_SRect& rectFrom,
  531.                                 FW_SRect& rectTo,
  532.                                 FW_HGDevice device,
  533.                                 ODTransform* transform)
  534. {
  535.     FW_SOM_TRY
  536.     {
  537.         CheckCache(mapping, ev, device, transform);
  538.         rectTo = FW_TransformCopy(ev, rectFrom, mapping.fLogicalToContentTransform);
  539.     }
  540.     FW_SOM_CATCH
  541. }
  542.  
  543. ODShape* SL_API FW_PrivMapping_LogicalToContentShape(
  544.                                 const FW_SMapping& mapping,
  545.                                 Environment* ev,
  546.                                 ODShape* shape,
  547.                                 FW_HGDevice device,
  548.                                 ODTransform* transform)
  549. {
  550.     ODShape* newShape = 0;
  551.  
  552.     FW_SOM_TRY
  553.     {
  554.         CheckCache(mapping, ev, device, transform);
  555.         newShape = shape->Copy(ev);
  556.         mapping.fLogicalToContentTransform->TransformShape(ev, newShape);
  557.     }
  558.     FW_SOM_CATCH
  559.  
  560.     return newShape;
  561. }
  562.  
  563. //----------------------------------------------------------------------------------------
  564. // ----- Logical ---> Device
  565. //----------------------------------------------------------------------------------------
  566.  
  567. void SL_API FW_PrivMapping_LogicalToDevicePoint(
  568.                                 const FW_SMapping& mapping,
  569.                                 Environment* ev,
  570.                                 const FW_SPoint& ptFrom,
  571.                                 FW_PlatformPoint& ptTo,
  572.                                 FW_HGDevice device,
  573.                                 ODTransform* transform)
  574. {
  575.     FW_SOM_TRY
  576.     {
  577.         CheckCache(mapping, ev, device, transform);
  578.         FW_CPoint pt = FW_TransformCopy(ev, ptFrom, mapping.fLogicalToDeviceTransform);
  579.         ptTo = pt.AsPlatformPoint();
  580.     }
  581.     FW_SOM_CATCH
  582. }
  583.  
  584. void SL_API FW_PrivMapping_LogicalToDeviceRect(
  585.                                 const FW_SMapping& mapping,
  586.                                 Environment* ev,
  587.                                 const FW_SRect& rectFrom,
  588.                                 FW_PlatformRect& rectTo,
  589.                                 FW_HGDevice device,
  590.                                 ODTransform* transform)
  591. {
  592.     FW_SOM_TRY
  593.     {
  594.         CheckCache(mapping, ev, device, transform);
  595.         FW_CRect rect = FW_TransformCopy(ev, rectFrom, mapping.fLogicalToDeviceTransform);
  596.         rectTo = rect.AsPlatformRect();
  597.     }
  598.     FW_SOM_CATCH
  599. }
  600.  
  601. ODShape* SL_API FW_PrivMapping_LogicalToDeviceShape(
  602.                                 const FW_SMapping& mapping,
  603.                                 Environment* ev,
  604.                                 ODShape* shape,
  605.                                 FW_HGDevice device,
  606.                                 ODTransform* transform)
  607. {
  608.     ODShape* newShape = 0;
  609.  
  610.     FW_SOM_TRY
  611.     {
  612.         CheckCache(mapping, ev, device, transform);
  613.         newShape = shape->Copy(ev);
  614.         mapping.fLogicalToDeviceTransform->TransformShape(ev, newShape);
  615.     }
  616.     FW_SOM_CATCH
  617.  
  618.     return newShape;
  619. }
  620.  
  621. //----------------------------------------------------------------------------------------
  622. // ----- Device ---> Logical
  623. //----------------------------------------------------------------------------------------
  624.  
  625. void SL_API FW_PrivMapping_DeviceToLogicalPoint(
  626.                                 const FW_SMapping& mapping,
  627.                                 Environment* ev,
  628.                                 const FW_PlatformPoint& ptFrom,
  629.                                 FW_SPoint& ptTo,
  630.                                 FW_HGDevice device,
  631.                                 ODTransform* transform)
  632. {
  633.     FW_SOM_TRY
  634.     {
  635.         CheckCache(mapping, ev, device, transform);
  636.         FW_CPoint pt = ptFrom;
  637.         ptTo = FW_InverseTransformCopy(ev, pt, mapping.fLogicalToDeviceTransform);
  638.     }
  639.     FW_SOM_CATCH
  640. }
  641.  
  642. void SL_API FW_PrivMapping_DeviceToLogicalRect(
  643.                                 const FW_SMapping& mapping,
  644.                                 Environment* ev,
  645.                                 const FW_PlatformRect& rectFrom,
  646.                                 FW_SRect& rectTo,
  647.                                 FW_HGDevice device,
  648.                                 ODTransform* transform)
  649. {
  650.     FW_SOM_TRY
  651.     {
  652.         CheckCache(mapping, ev, device, transform);
  653.         FW_CRect rect = rectFrom;
  654.         rectTo = rect.InverseTransformCopy(ev, mapping.fLogicalToDeviceTransform);
  655.     }
  656.     FW_SOM_CATCH
  657. }
  658.     
  659. ODShape* SL_API FW_PrivMapping_DeviceToLogicalShape(
  660.                                 const FW_SMapping& mapping,
  661.                                 Environment* ev,
  662.                                 ODShape* shape,
  663.                                 FW_HGDevice device,
  664.                                 ODTransform* transform)
  665. {
  666.     ODShape* newShape = 0;
  667.  
  668.     FW_SOM_TRY
  669.     {
  670.         CheckCache(mapping, ev, device, transform);
  671.         newShape = shape->Copy(ev);
  672.         mapping.fLogicalToDeviceTransform->InvertShape(ev, newShape);
  673.     }
  674.     FW_SOM_CATCH
  675.  
  676.     return newShape;
  677. }
  678.  
  679. //----------------------------------------------------------------------------------------
  680. // ----- Device ---> Content
  681. //----------------------------------------------------------------------------------------
  682.  
  683. void SL_API FW_PrivMapping_DeviceToContentPoint(
  684.                                 const FW_SMapping& mapping,
  685.                                 Environment* ev,
  686.                                 const FW_PlatformPoint& ptFrom,
  687.                                 FW_SPoint& ptTo,
  688.                                 FW_HGDevice device,
  689.                                 ODTransform* transform)
  690. {
  691.     FW_SOM_TRY
  692.     {
  693.         CheckCache(mapping, ev, device, transform);
  694.         FW_CPoint pt = ptFrom;
  695.         ptTo = FW_InverseTransformCopy(ev, pt, mapping.fContentToDeviceTransform);
  696.     }
  697.     FW_SOM_CATCH
  698. }
  699.  
  700. void SL_API FW_PrivMapping_DeviceToContentRect(
  701.                                 const FW_SMapping& mapping,
  702.                                 Environment* ev,
  703.                                 const FW_PlatformRect& rectFrom,
  704.                                 FW_SRect& rectTo,
  705.                                 FW_HGDevice device,
  706.                                 ODTransform* transform)
  707. {
  708.     FW_SOM_TRY
  709.     {
  710.         CheckCache(mapping, ev, device, transform);
  711.         FW_CRect rect = rectFrom;
  712.         rectTo = rect.InverseTransformCopy(ev, mapping.fContentToDeviceTransform);
  713.     }
  714.     FW_SOM_CATCH
  715. }
  716.  
  717. ODShape* SL_API FW_PrivMapping_DeviceToContentShape(
  718.                                 const FW_SMapping& mapping,
  719.                                 Environment* ev,
  720.                                 ODShape* shape,
  721.                                 FW_HGDevice device,
  722.                                 ODTransform* transform)
  723. {
  724.     ODShape* newShape = 0;
  725.  
  726.     FW_SOM_TRY
  727.     {
  728.         CheckCache(mapping, ev, device, transform);
  729.         newShape = shape->Copy(ev);
  730.         mapping.fContentToDeviceTransform->InvertShape(ev, newShape);
  731.     }
  732.     FW_SOM_CATCH
  733.  
  734.     return newShape;
  735. }
  736.  
  737. //----------------------------------------------------------------------------------------
  738. // ----- Content ---> Logical
  739. //----------------------------------------------------------------------------------------
  740.                             
  741. void SL_API FW_PrivMapping_ContentToLogicalPoint(
  742.                                 const FW_SMapping& mapping,
  743.                                 Environment* ev,
  744.                                 const FW_SPoint& ptFrom,
  745.                                 FW_SPoint& ptTo,
  746.                                 FW_HGDevice device,
  747.                                 ODTransform* transform)
  748. {
  749.     FW_SOM_TRY
  750.     {
  751.         CheckCache(mapping, ev, device, transform);
  752.         ptTo = FW_InverseTransformCopy(ev, ptFrom, mapping.fLogicalToContentTransform);
  753.     }
  754.     FW_SOM_CATCH
  755. }
  756.     
  757. void SL_API FW_PrivMapping_ContentToLogicalRect(
  758.                                 const FW_SMapping& mapping,
  759.                                 Environment* ev,
  760.                                 const FW_SRect& rectFrom,
  761.                                 FW_SRect& rectTo,
  762.                                 FW_HGDevice device,
  763.                                 ODTransform* transform)
  764. {
  765.     FW_SOM_TRY
  766.     {
  767.         CheckCache(mapping, ev, device, transform);
  768.         rectTo = FW_InverseTransformCopy(ev, rectFrom, mapping.fLogicalToContentTransform);
  769.     }
  770.     FW_SOM_CATCH
  771. }
  772.                                 
  773.     
  774. ODShape* SL_API FW_PrivMapping_ContentToLogicalShape(
  775.                                 const FW_SMapping& mapping,
  776.                                 Environment* ev,
  777.                                 ODShape* shape,
  778.                                 FW_HGDevice device,
  779.                                 ODTransform* transform)
  780. {
  781.     ODShape* newShape = 0;
  782.  
  783.     FW_SOM_TRY
  784.     {
  785.         CheckCache(mapping, ev, device, transform);
  786.         newShape = shape->Copy(ev);
  787.         mapping.fLogicalToContentTransform->InvertShape(ev, newShape);
  788.     }
  789.     FW_SOM_CATCH
  790.  
  791.     return newShape;
  792. }
  793.  
  794. //----------------------------------------------------------------------------------------
  795. // ----- Content ---> Device
  796. //----------------------------------------------------------------------------------------
  797.  
  798. void SL_API FW_PrivMapping_ContentToDevicePoint(
  799.                                 const FW_SMapping& mapping,
  800.                                 Environment* ev,
  801.                                 const FW_SPoint& ptFrom,
  802.                                 FW_PlatformPoint& ptTo,
  803.                                 FW_HGDevice device,
  804.                                 ODTransform* transform)
  805. {
  806.     FW_SOM_TRY
  807.     {
  808.         CheckCache(mapping, ev, device, transform);
  809.         FW_CPoint pt = FW_TransformCopy(ev, ptFrom, mapping.fContentToDeviceTransform);
  810.         ptTo = pt.AsPlatformPoint();
  811.     }
  812.     FW_SOM_CATCH
  813. }
  814.  
  815. void SL_API FW_PrivMapping_ContentToDeviceRect(
  816.                                 const FW_SMapping& mapping,
  817.                                 Environment* ev,
  818.                                 const FW_SRect& rectFrom,
  819.                                 FW_PlatformRect& rectTo,
  820.                                 FW_HGDevice device,
  821.                                 ODTransform* transform)
  822. {
  823.     FW_SOM_TRY
  824.     {
  825.         CheckCache(mapping, ev, device, transform);
  826.         FW_CRect rect = FW_TransformCopy(ev, rectFrom, mapping.fContentToDeviceTransform);
  827.         rectTo = rect.AsPlatformRect();
  828.     }
  829.     FW_SOM_CATCH
  830. }
  831.  
  832. ODShape* SL_API FW_PrivMapping_ContentToDeviceShape(
  833.                                 const FW_SMapping& mapping,
  834.                                 Environment* ev,
  835.                                 ODShape* shape,
  836.                                 FW_HGDevice device,
  837.                                 ODTransform* transform)
  838. {
  839.     ODShape* newShape = 0;
  840.  
  841.     FW_SOM_TRY
  842.     {
  843.         CheckCache(mapping, ev, device, transform);
  844.         newShape = shape->Copy(ev);
  845.         mapping.fContentToDeviceTransform->TransformShape(ev, newShape);
  846.     }
  847.     FW_SOM_CATCH
  848.  
  849.     return newShape;
  850. }
  851.  
  852.