@@ -42,6 +42,7 @@ impl Renderable for PathObject {
42
42
_ofd : & mut Ofd , _document : & Document ) -> Result < ( ) , Error > {
43
43
context. save ( ) ?;
44
44
45
+ // TODO(hualet): implement ctm.
45
46
let boundary = ct:: Box :: from ( self . boundary . clone ( ) ) . to_pixel ( ) ;
46
47
let color = ct:: Color :: from (
47
48
self . stroke_color . as_ref ( ) . unwrap ( ) . value . clone ( ) ) ;
@@ -89,8 +90,21 @@ impl Renderable for TextObject {
89
90
context. set_source_rgb ( fill_color. value [ 0 ] as f64 / 255.0 ,
90
91
fill_color. value [ 1 ] as f64 / 255.0 ,
91
92
fill_color. value [ 2 ] as f64 / 255.0 ) ;
92
- context. move_to ( boundary. x as f64 + mmtopx ( self . text_code . x ) ,
93
+
94
+ // NOTE(hualet): transform should be used together with translate,
95
+ // so the coordinate system is correct.
96
+ // THEY ARE BOTH TRANSFORMATIONS!
97
+ context. translate ( boundary. x as f64 + mmtopx ( self . text_code . x ) ,
93
98
boundary. y as f64 + mmtopx ( self . text_code . y ) ) ;
99
+ if let Some ( ctm) = self . ctm . as_ref ( ) {
100
+ debug ! ( "render text object:{:?} with ctm: {:?}" ,
101
+ self . text_code. value, ctm) ;
102
+ let matrix = ct:: Matrix :: from ( ctm. clone ( ) ) ;
103
+ let cairo_matrix: cairo:: Matrix = matrix. into ( ) ;
104
+ context. transform ( cairo_matrix) ;
105
+ }
106
+
107
+ context. move_to ( 0. , 0. ) ;
94
108
context. show_text ( self . text_code . value . as_str ( ) ) ?;
95
109
96
110
context. restore ( )
@@ -103,6 +117,7 @@ impl Renderable for ImageObject {
103
117
ofd : & mut Ofd , document : & Document ) -> Result < ( ) , Error > {
104
118
context. save ( ) ?;
105
119
120
+ // TODO(hualet): implement ctm.
106
121
let boundary = ct:: Box :: from ( self . boundary . clone ( ) ) . to_pixel ( ) ;
107
122
108
123
// find the image file:
@@ -178,4 +193,39 @@ fn _render_page_block(events: Vec<Event>, context: &mut cairo::Context,
178
193
}
179
194
180
195
Ok ( ( ) )
196
+ }
197
+
198
+ /*
199
+ ct::Matrix
200
+
201
+ | a b 0 |
202
+ | c d 0 |
203
+ | e f 1 |
204
+
205
+ x'=ax+cy+e
206
+ y'=bx+dy+f
207
+
208
+
209
+ cairo::Matrix
210
+
211
+ typedef struct {
212
+ double xx; double yx;
213
+ double xy; double yy;
214
+ double x0; double y0;
215
+ } cairo_matrix_t;
216
+
217
+ x_new = xx * x + xy * y + x0;
218
+ y_new = yx * x + yy * y + y0;
219
+ */
220
+ impl From < ct:: Matrix > for cairo:: Matrix {
221
+ fn from ( value : ct:: Matrix ) -> Self {
222
+ Self :: new (
223
+ value. a , // xx
224
+ value. b , // yx
225
+ value. c , // xy
226
+ value. d , // yy
227
+ value. e , // x0
228
+ value. f // y0
229
+ )
230
+ }
181
231
}
0 commit comments