Mercurial > hg > octave-lojdl
diff libinterp/corefcn/txt-latex.cc @ 17436:d415dc6ac1e2
Added horizontal/vertical alignment and rotation to latex_render class
author | Andrej Lojdl <andrej.lojdl@gmail.com> |
---|---|
date | Tue, 17 Sep 2013 16:20:47 +0200 (2013-09-17) |
parents | 71b6f8a81e80 |
children | fd3e999305ea |
line wrap: on
line diff
--- a/libinterp/corefcn/txt-latex.cc +++ b/libinterp/corefcn/txt-latex.cc @@ -347,6 +347,21 @@ ::warning ("latex_render::set_color: invalid color"); } +int +latex_render::rotation_to_mode (double rotation) const +{ + if (rotation == 0.0) + return ROTATION_0; + else if (rotation == 90.0) + return ROTATION_90; + else if (rotation == 180.0) + return ROTATION_180; + else if (rotation == 270.0) + return ROTATION_270; + else + return ROTATION_0; +} + void latex_render::text_to_pixels (const std::string& txt, @@ -385,7 +400,78 @@ case 3: break; case 4: bbox(1) = -bbox(3)-bbox(1); break; } + + int rot_mode = rotation_to_mode (rotation); + + switch (rot_mode) + { + case ROTATION_90: + std::swap (bbox(0), bbox(1)); + std::swap (bbox(2), bbox(3)); + bbox(0) = -bbox(0)-bbox(2); + break; + case ROTATION_180: + bbox(0) = -bbox(0)-bbox(2); + bbox(1) = -bbox(1)-bbox(3); + break; + case ROTATION_270: + std::swap (bbox(0), bbox(1)); + std::swap (bbox(2), bbox(3)); + bbox(1) = -bbox(1)-bbox(3); + break; + } } + + /* Rotating pixels */ + int rot_mode = rotation_to_mode (rotation); + + if (pixels.numel () > 0) + { + switch (rot_mode) + { + case ROTATION_0: + break; + case ROTATION_90: + { + Array<octave_idx_type> perm (dim_vector (3, 1)); + perm(0) = 0; + perm(1) = 2; + perm(2) = 1; + pixels = pixels.permute (perm); + + Array<idx_vector> idx (dim_vector (3, 1)); + idx(0) = idx_vector (':'); + idx(1) = idx_vector (pixels.dim2 ()-1, -1, -1); + idx(2) = idx_vector (':'); + pixels = uint8NDArray (pixels.index (idx)); + } + break; + case ROTATION_180: + { + Array<idx_vector> idx (dim_vector (3, 1)); + idx(0) = idx_vector (':'); + idx(1) = idx_vector (pixels.dim2 ()-1, -1, -1); + idx(2)= idx_vector (pixels.dim3 ()-1, -1, -1); + pixels = uint8NDArray (pixels.index (idx)); + } + break; + case ROTATION_270: + { + Array<octave_idx_type> perm (dim_vector (3, 1)); + perm(0) = 0; + perm(1) = 2; + perm(2) = 1; + pixels = pixels.permute (perm); + + Array<idx_vector> idx (dim_vector (3, 1)); + idx(0) = idx_vector (':'); + idx(1) = idx_vector (':'); + idx(2) = idx_vector (pixels.dim3 ()-1, -1, -1); + pixels = uint8NDArray (pixels.index (idx)); + } + break; + } + } } Matrix