1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
/*
* legend_tile.cc -- ePiX screen implemenation for legends
*
* This file is part of ePiX, a C++ library for creating high-quality
* figures in LaTeX
*
* Version 1.2.1
* Last Change: September 28, 2007
*/
/*
* Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
* Andrew D. Hwang <ahwang -at- holycross -dot- edu>
* Department of Mathematics and Computer Science
* College of the Holy Cross
* Worcester, MA, 01610-2395, USA
*/
/*
* ePiX is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* ePiX is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ePiX; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <string>
#include <sstream>
#include <list>
#include "enums.h"
#include "length.h"
#include "label_style.h"
#include "pen_data.h"
#include "functions.h"
#include "pairs.h"
#include "affine.h"
#include "screen_mask.h"
#include "picture.h"
#include "picture_data.h"
#include "format.h"
#include "legend_item.h"
#include "legend_tile.h"
namespace ePiX {
// location, offsets, contents, mark type, visibility
legend_tile::legend_tile(const pair& here, const pair& offset,
epix_label_posn align, const label_state& style,
const pen_data& pen,
double key_size, double skip,
std::list<legend_item*> items)
: m_here(here), m_offset(offset), m_align(align), m_style(style),
m_item_border(pen), m_key_size(key_size), m_label_skip(skip)
{
for (std::list<legend_item*>::const_iterator li=items.begin();
li != items.end(); ++li)
m_items.push_back((*li)->clone());
}
legend_tile::legend_tile(const legend_tile& L)
: m_here(L.m_here), m_offset(L.m_offset), m_align(L.m_align),
m_style(L.m_style), m_item_border(L.m_item_border),
m_key_size(L.m_key_size), m_label_skip(L.m_label_skip)
{
for (std::list<legend_item*>::const_iterator ip = L.m_items.begin();
ip != L.m_items.end(); ++ip)
m_items.push_back((*ip)->clone());
}
legend_tile& legend_tile::operator=(const legend_tile& L)
{
if (&L != this)
{
std::list<legend_item*> tmp;
for (std::list<legend_item*>::const_iterator ip = L.m_items.begin();
ip != L.m_items.end(); ++ip)
tmp.push_back((*ip)->clone());
m_here = L.m_here;
m_offset = L.m_offset;
m_align = L.m_align;
m_style = L.m_style;
m_item_border = L.m_item_border;
m_key_size = L.m_key_size;
m_label_skip = L.m_label_skip;
swap(m_items, tmp);
}
return *this;
}
legend_tile::~legend_tile()
{
for (std::list<legend_item*>::iterator ip = m_items.begin();
ip != m_items.end(); ++ip)
delete *ip;
}
legend_tile& legend_tile::map_by(const affine& f)
{
m_here = f(m_here);
return *this;
}
// legends unaffected by cropping
legend_tile& legend_tile::crop_to(const screen_mask& M)
{
/*
if (M.crops(m_here))
m_seen = false;
*/
return *this;
}
legend_tile* legend_tile::clone() const
{
return new legend_tile(*this);
}
bool legend_tile::is_empty() const
{
return false;
}
std::string legend_tile::print_to(const format& fmt,
const std::string& len) const
{
std::stringstream obuf, item_buf;
item_buf << "%" << std::endl << "\\begin{tabular}{l}%" << std::endl;
for (std::list<legend_item*>::const_iterator ip=m_items.begin();
ip != m_items.end(); ++ip)
item_buf << (*ip)->key(fmt, m_key_size, m_item_border, len)
<< "\\hskip " << m_label_skip << "pt "
<< fmt.print_latex_hbox(m_style, (*ip)->value())
<< " \\\\" << std::endl;
item_buf << "\\end{tabular}%" << std::endl;
obuf << fmt.print_text(m_here, m_offset, item_buf.str(), m_style, len);
return obuf.str();
}
void legend_tile::add_to_palette() const
{
the_picture().add_to_palette(m_item_border.color())
.add_to_palette(m_style.text_color())
.add_to_palette(m_style.mask_color())
.add_to_palette(m_style.label_border().color());
}
} // end of namespace
|