InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
PMUtils.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Eric_Kenninga
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 __PMUTILS__
25 #define __PMUTILS__
26 
27 #ifndef __PMTYPES__
28 #include "PMTypes.h"
29 #endif
30 
31 inline uchar HighByte(uint16 b)
32  { return (uchar)(b >> 8); }
33 inline uchar LowByte(uint16 b)
34  { return (uchar)(b & 0x00FF); }
35 
36 inline uint16 LoWrd(uint32 l)
37  { return (uint16)(l); }
38 inline uint16 HiWrd(uint32 l)
39  { return (uint16)(l >> 16); }
40 
41 template <class T>
42 inline T minimum(const T& a1, const T& b1)
43  { return a1 < b1 ? a1 : b1; }
44 
45 template <class T>
46 inline T maximum(const T& a1, const T& b1)
47  { return b1 < a1 ? a1 : b1; }
48 
49 //inline int32 abs(int32 a)
50 // { return a < 0 ? -a : a; }
51 
52 inline int32 sign(double a)
53  { return (a > 0.0 ? 1 : (a == 0.0 ? 0 : -1)); }
54 
55 inline int32 sign(int32 a)
56  { return (a > 0 ? 1 : (a == 0 ? 0 : -1)); }
57 
58 inline bool32 Even(int32 x)
59  { return (bool32)(!(x & 1)); }
60 inline bool32 Odd(int32 x)
61  { return (bool32)(x & 1); }
62 
63 const double kFixedScale = 65536.0;
64 const double kInverseFixedScale = 0.0000152587890625;
65 
66 // Inbound Conversions
67 inline PMReal ToRealNumber(Fixed fx)
68  { return int32(fx) * kInverseFixedScale; }
69 
70 // Reset FPU exception register.
71 // Fix for bug# 306191. Win95/98 printer drivers reset the floation point
72 // exceptions on Windows. This causes floating point exceptions to be translated
73 // to Windows structured exceptions. We don't want this. This is *not* the default
74 // behavior in K2. [jshankar 5/26/99]
75 #if defined(WINDOWS)
76 
77 inline void ResetFPUException()
78 {
79  if (kDefaultFPUExceptions != _control87(0,0))
80 #if !defined(_WIN64)
81  _control87( kDefaultFPUExceptions, 0xfffff );
82 #else
83  // on 64 bit architecture changing the floating point precision is not supported
84  // so _MCW_PC flag is not supported . Also _MCW_IC flag is not supported on 64 bit architecture
85  _control87( kDefaultFPUExceptions, _MCW_DN | _MCW_EM | _MCW_RC);
86 #endif
87 }
88 
89 #elif defined(MACINTOSH) || defined(WASM)
90 
91 inline void ResetFPUException()
92 {
93  // do nothing on Macintosh
94 }
95 
96 #endif
97 
98 // Convenience define for element count for a C-array
99 #define ELEM_COUNT(array) (sizeof(array)/sizeof(array[0]))
100 
101 
102 #endif // PMUTILS