Mercurial > hg > octave-lojdl
changeset 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 |
parents | 499fc170bca3 |
children | a46a648a2de2 |
files | libinterp/corefcn/txt-latex.cc libinterp/corefcn/txt-latex.h |
diffstat | 2 files changed, 95 insertions(+), 0 deletions(-) [+] |
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
--- a/libinterp/corefcn/txt-latex.h +++ b/libinterp/corefcn/txt-latex.h @@ -35,6 +35,14 @@ latex_render : public base_text_render { public: + enum { + ROTATION_0 = 0, + ROTATION_90 = 1, + ROTATION_180 = 2, + ROTATION_270 = 3 + }; + +public: latex_render (void); ~latex_render (void); @@ -61,6 +69,7 @@ uint8NDArray render (void); private: + int rotation_to_mode (double rotation) const; int font_size; std::string font_name,directory_path; Matrix bbox;