Compute coefficients for an affine matrix describing the rotation of the text. If the text is right-to-left such as Arabic or Hebrew, we reflect over the Y-axis. This matrix will set the coordinate system for placing text in the PDF file. RTL [ x' ] = [ a b ][ x ] = [-1 0 ] [ cos sin ][ x ] [ y' ] [ c d ][ y ] [ 0 1 ] [-sin cos ][ y ]
| 273 | // [ x' ] = [ a b ][ x ] = [-1 0 ] [ cos sin ][ x ] |
| 274 | // [ y' ] [ c d ][ y ] [ 0 1 ] [-sin cos ][ y ] |
| 275 | void AffineMatrix(int writing_direction, |
| 276 | int line_x1, int line_y1, int line_x2, int line_y2, |
| 277 | double *a, double *b, double *c, double *d) { |
| 278 | double theta = atan2(static_cast<double>(line_y1 - line_y2), |
| 279 | static_cast<double>(line_x2 - line_x1)); |
| 280 | *a = cos(theta); |
| 281 | *b = sin(theta); |
| 282 | *c = -sin(theta); |
| 283 | *d = cos(theta); |
| 284 | switch(writing_direction) { |
| 285 | case WRITING_DIRECTION_RIGHT_TO_LEFT: |
| 286 | *a = -*a; |
| 287 | *b = -*b; |
| 288 | break; |
| 289 | case WRITING_DIRECTION_TOP_TO_BOTTOM: |
| 290 | // TODO(jbreiden) Consider using the vertical PDF writing mode. |
| 291 | break; |
| 292 | default: |
| 293 | break; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | // There are some really awkward PDF viewers in the wild, such as |
| 298 | // 'Preview' which ships with the Mac. They do a better job with text |