• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "pptypes.h"
2 #include <utility>
3 #include <stdio.h>
4 #include <assert.h>
5 
Position_dump(Position pos)6 void Position_dump(Position pos) // {{{
7 {
8   static const char *pstr[3]={"Left/Bottom","Center","Right/Top"};
9   if ((pos < LEFT) || (pos > RIGHT)) {
10     fprintf(stderr,"(bad position: %d)",pos);
11   } else {
12     fputs(pstr[pos+1],stderr);
13   }
14 }
15 // }}}
16 
Position_dump(Position pos,Axis axis)17 void Position_dump(Position pos,Axis axis) // {{{
18 {
19   assert((axis == Axis::X) || (axis == Axis::Y));
20   if ((pos < LEFT) || (pos > RIGHT)) {
21     fprintf(stderr,"(bad position: %d)",pos);
22     return;
23   }
24   if (axis==Axis::X) {
25     static const char *pxstr[3]={"Left","Center","Right"};
26     fputs(pxstr[pos+1],stderr);
27   } else {
28     static const char *pystr[3]={"Bottom","Center","Top"};
29     fputs(pystr[pos+1],stderr);
30   }
31 }
32 // }}}
33 
Rotation_dump(Rotation rot)34 void Rotation_dump(Rotation rot) // {{{
35 {
36   static const char *rstr[4]={"0 deg","90 deg","180 deg","270 deg"}; // CCW
37   if ((rot < ROT_0) || (rot > ROT_270)) {
38     fprintf(stderr,"(bad rotation: %d)",rot);
39   } else {
40     fputs(rstr[rot],stderr);
41   }
42 }
43 // }}}
44 
operator +(Rotation lhs,Rotation rhs)45 Rotation operator+(Rotation lhs,Rotation rhs) // {{{
46 {
47   return (Rotation)(((int)lhs+(int)rhs)%4);
48 }
49 // }}}
50 
operator -(Rotation lhs,Rotation rhs)51 Rotation operator-(Rotation lhs,Rotation rhs) // {{{
52 {
53   return (Rotation)((((int)lhs-(int)rhs)%4+4)%4);
54 }
55 // }}}
56 
operator -(Rotation rhs)57 Rotation operator-(Rotation rhs) // {{{
58 {
59   return (Rotation)((4-(int)rhs)%4);
60 }
61 // }}}
62 
BorderType_dump(BorderType border)63 void BorderType_dump(BorderType border) // {{{
64 {
65   if ((border < NONE) || (border == 1) || (border > TWO_THICK)) {
66     fprintf(stderr,"(bad border: %d)",border);
67   } else {
68     static const char *bstr[6]={"None",NULL,"one thin","one thick","two thin","two thick"};
69     fputs(bstr[border],stderr);
70   }
71 }
72 // }}}
73 
rotate_move(Rotation r,float pwidth,float pheight)74 void PageRect::rotate_move(Rotation r,float pwidth,float pheight) // {{{
75 {
76 #if 1
77   if (r>=ROT_180) {
78     std::swap(top,bottom);
79     std::swap(left,right);
80   }
81   if ((r == ROT_90) || (r == ROT_270)) {
82     const float tmp=bottom;
83     bottom=left;
84     left=top;
85     top=right;
86     right=tmp;
87 
88     std::swap(width,height);
89     std::swap(pwidth,pheight);
90   }
91   if ((r == ROT_90) || (r == ROT_180)) {
92     left=pwidth-left;
93     right=pwidth-right;
94   }
95   if ((r == ROT_270) || (r == ROT_180)) {
96     top=pheight-top;
97     bottom=pheight-bottom;
98   }
99 #else
100   switch (r) {
101   case ROT_0: // no-op
102     break;
103   case ROT_90:
104     const float tmp0=bottom;
105     bottom=left;
106     left=pheight-top;
107     top=right;
108     right=pheight-tmp0;
109 
110     std::swap(width,height);
111     break;
112   case ROT_180:
113     const float tmp1=left;
114     left=pwidth-right;
115     right=pwidth-tmp1;
116 
117     const float tmp2=top;
118     top=pheight-bottom;
119     bottom=pheight-tmp2;
120     break;
121   case ROT_270:
122     const float tmp3=top;
123     top=pwidth-left;
124     left=bottom;
125     bottom=pwidth-right;
126     right=tmp3;
127 
128     std::swap(width,height);
129     break;
130   }
131 #endif
132 }
133 // }}}
134 
scale(float mult)135 void PageRect::scale(float mult) // {{{
136 {
137   if (mult==1.0) {
138     return;
139   }
140   assert(mult!=0.0);
141 
142   bottom*=mult;
143   left*=mult;
144   top*=mult;
145   right*=mult;
146 
147   width*=mult;
148   height*=mult;
149 }
150 // }}}
151 
translate(float tx,float ty)152 void PageRect::translate(float tx,float ty) // {{{
153 {
154   left+=tx;
155   bottom+=ty;
156   right+=tx;
157   top+=ty;
158 }
159 // }}}
160 
set(const PageRect & rhs)161 void PageRect::set(const PageRect &rhs) // {{{
162 {
163   if (!std::isnan(rhs.top)) top=rhs.top;
164   if (!std::isnan(rhs.left)) left=rhs.left;
165   if (!std::isnan(rhs.right)) right=rhs.right;
166   if (!std::isnan(rhs.bottom)) bottom=rhs.bottom;
167 }
168 // }}}
169 
dump() const170 void PageRect::dump() const // {{{
171 {
172   fprintf(stderr,"top: %f, left: %f, right: %f, bottom: %f\n"
173 	  "width: %f, height: %f\n",
174 	  top,left,right,bottom,
175 	  width,height);
176 }
177 // }}}
178