1 /* 2 * label_data.cc -- ePiX::label_data class 3 * 4 * This file is part of ePiX, a C++ library for creating high-quality 5 * figures in LaTeX 6 * 7 * Version 1.1.21 8 * Last Change: September 22, 2007 9 */ 10 11 /* 12 * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 13 * Andrew D. Hwang <rot 13 nujnat at zngupf dot ubylpebff dot rqh> 14 * Department of Mathematics and Computer Science 15 * College of the Holy Cross 16 * Worcester, MA, 01610-2395, USA 17 */ 18 19 /* 20 * ePiX is free software; you can redistribute it and/or modify it 21 * under the terms of the GNU General Public License as published by 22 * the Free Software Foundation; either version 2 of the License, or 23 * (at your option) any later version. 24 * 25 * ePiX is distributed in the hope that it will be useful, but WITHOUT 26 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 27 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 28 * License for more details. 29 * 30 * You should have received a copy of the GNU General Public License 31 * along with ePiX; if not, write to the Free Software Foundation, Inc., 32 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 33 */ 34 35 #include <sstream> 36 37 #include "enums.h" 38 39 #include "triples.h" 40 #include "pairs.h" 41 42 #include "label_data.h" 43 #include "camera.h" 44 #include "screen_data.h" 45 #include "screen.h" 46 47 #include "clipping.h" 48 49 #include "paint_style.h" 50 51 #include "active_screen.h" 52 #include "glyph.h" 53 54 namespace ePiX { 55 label_data(const P & here,const P & offset,const std::string & text,epix_mark_type mark)56 label_data::label_data(const P& here, const P& offset, 57 const std::string& text, epix_mark_type mark) 58 : m_here(here), m_offset(offset.x1(), offset.x2()), 59 m_text(text), m_mark(mark), m_sizes(the_mark_size()), 60 m_style(the_label_style()), m_seen(!the_clip_box().clips(m_here)) 61 { 62 // set axis tick color to line color; rotation ok if requested 63 if (m_mark == HTICK || m_mark == VTICK) 64 m_style.text_color(the_paint_style().line_color()); 65 } 66 67 // generate label text from user-specified function of 2 or 3 variables label_data(const P & here,const P & offset,std::string f (double,double),epix_mark_type mark)68 label_data::label_data(const P& here, const P& offset, 69 std::string f(double,double), epix_mark_type mark) 70 : m_here(here), m_offset(offset.x1(), offset.x2()), 71 m_text(f(here.x1(), here.x2())), 72 m_mark(mark), m_sizes(the_mark_size()), m_style(the_label_style()), 73 m_seen(!the_clip_box().clips(m_here)) 74 { 75 if (m_mark == HTICK || m_mark == VTICK) 76 m_style.text_color(the_paint_style().line_color()); 77 } 78 label_data(const P & here,const P & offset,std::string f (double,double,double),epix_mark_type mark)79 label_data::label_data(const P& here, const P& offset, 80 std::string f(double,double,double), 81 epix_mark_type mark) 82 : m_here(here), m_offset(offset.x1(), offset.x2()), 83 m_text(f(here.x1(), here.x2(), here.x3())), 84 m_mark(mark), m_sizes(the_mark_size()), m_style(the_label_style()), 85 m_seen(!the_clip_box().clips(m_here)) 86 { 87 if (m_mark == HTICK || m_mark == VTICK) 88 m_style.text_color(the_paint_style().line_color()); 89 } 90 91 // markers subject to masking, border 92 // Only this constructor aligns TICK marks, prevents their rotation label_data(const P & here,epix_mark_type mark,epix_label_posn A)93 label_data::label_data(const P& here, epix_mark_type mark, epix_label_posn A) 94 : m_here(here), m_offset(0, 0), 95 m_text(""), m_mark(mark), m_sizes(the_mark_size()), 96 m_style(the_label_style()), m_seen(!the_clip_box().clips(m_here)) 97 { 98 if (m_mark == HTICK || m_mark == VTICK) 99 { 100 m_style.text_color(the_paint_style().line_color()); 101 m_style.label_angle(0); // no initial rotation 102 103 // prevent unseemly alignment; default is c, so needn't check 104 if (m_mark == HTICK && A == t || A == b) 105 m_style.align_to(A); 106 107 else if (A == l || A == r) 108 m_style.align_to(A); 109 } 110 } 111 112 text_color(const Color & col)113 label_data& label_data::text_color(const Color& col) 114 { 115 m_style.text_color(col); 116 return *this; 117 } 118 mask_color(const Color & col)119 label_data& label_data::mask_color(const Color& col) 120 { 121 m_style.mask_color(col); 122 return *this; 123 } 124 align_to(epix_label_posn align)125 label_data& label_data::align_to(epix_label_posn align) 126 { 127 m_style.align_to(align); 128 return *this; 129 } 130 131 // send colors through cam draw() const132 void label_data::draw() const 133 { 134 if (m_seen) 135 (*active_screen()).m_screen->add_tile(glyph(cam()(m_here), m_offset, 136 m_text, m_mark, m_sizes, 137 m_style.seen_through(cam()), 138 true)); 139 } 140 } // end of namespace 141