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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
|
/* $Id: VisioText.cpp,v 1.4 2009/06/03 01:10:57 ellson Exp $ $Revision: 1.4 $ */
/* vim:set shiftwidth=4 ts=8: */
/**********************************************************
* This software is part of the graphviz package *
* http://www.graphviz.org/ *
* *
* Copyright (c) 1994-2004 AT&T Corp. *
* and is licensed under the *
* Common Public License, Version 1.0 *
* by AT&T Corp. *
* *
* Information and Software Systems Research *
* AT&T Research, Florham Park NJ *
**********************************************************/
#include "VisioText.h"
#include "gvcjob.h"
#include "gvio.h"
extern "C" char *xml_string(char* str);
namespace Visio
{
static const float INCHES_PER_POINT = 1.0 / 72.0;
Char::Char(double size, unsigned char red, unsigned char green, unsigned char blue):
_size(size),
_red(red),
_green(green),
_blue(blue)
{
}
void Char::Print(GVJ_t* job) const
{
gvputs(job, "<Char>\n");
gvprintf(job, "<Color>#%02X%02X%02X</Color>\n", _red, _green, _blue);
gvprintf(job, "<Size>%f</Size>\n", _size * job->scale.x * INCHES_PER_POINT); /* scale font size, VDX uses inches */
gvputs(job, "</Char>\n");
}
Para::Para(HorzAlign horzAlign):
_horzAlign(horzAlign)
{
}
void Para::Print(GVJ_t* job) const
{
gvputs(job, "<Para>\n");
gvprintf(job, "<HorzAlign>%d</HorzAlign>\n", _horzAlign);
gvputs(job, "</Para>\n");
}
Run::Run(boxf bounds, char* text):
_bounds(bounds),
_text(agstrdup(text)) /* copy text */
{
}
Run::~Run()
{
/* since we copied, we need to free */
agstrfree(_text);
}
boxf Run::GetBounds() const
{
return _bounds;
}
void Run::Print(GVJ_t* job, unsigned int index) const
{
gvprintf(job, "<pp IX='%d'/><cp IX='%d'/>%s\n", index, index, _text ? xml_string(_text) : ""); /* para mark + char mark + actual text */
}
Text* Text::CreateText(GVJ_t* job, pointf p, textpara_t* para)
{
Para::HorzAlign horzAlign;
/* compute text bounding box and VDX horizontal align */
boxf bounds;
bounds.LL.y = p.y + para->yoffset_centerline;
bounds.UR.y = p.y + para->yoffset_centerline + para->height;
double width = para->width;
switch (para->just)
{
case 'r':
horzAlign = Para::horzRight;
bounds.LL.x = p.x - width;
bounds.UR.x = p.x;
break;
case 'l':
horzAlign = Para::horzLeft;
bounds.LL.x = p.x;
bounds.UR.x = p.x + width;
break;
case 'n':
default:
horzAlign = Para::horzCenter;
bounds.LL.x = p.x - width / 2.0;
bounds.UR.x = p.x + width / 2.0;
break;
}
return new Text(
new Para(
horzAlign),
new Char(
para->fontsize,
job->obj->pencolor.u.rgba[0],
job->obj->pencolor.u.rgba[1],
job->obj->pencolor.u.rgba[2]),
new Run(
bounds,
para->str));
}
Text::Text(Para* para, Char* chars, Run* run):
_para(para),
_chars(chars),
_run(run)
{
}
Text::~Text()
{
if (_para)
delete _para;
if (_chars)
delete _chars;
if (_run)
delete _run;
}
boxf Text::GetBounds() const
{
return _run->GetBounds();
}
void Text::Print(GVJ_t* job) const
{
if (_para)
_para->Print(job);
if (_chars)
_chars->Print(job);
}
void Text::PrintRun(GVJ_t* job, unsigned int index) const
{
if (_run)
_run->Print(job, index);
}
Hyperlink* Hyperlink::CreateHyperlink(GVJ_t* job, char* url, char* tooltip, char* target, char* id)
{
return new Hyperlink(tooltip, url, target);
}
Hyperlink::Hyperlink(char* description, char* address, char* frame):
_description(agstrdup(description)),
_address(agstrdup(address)),
_frame(agstrdup(frame))
{
}
Hyperlink::~Hyperlink()
{
agstrfree(_description);
agstrfree(_address);
agstrfree(_frame);
}
/* output the hyperlink */
void Hyperlink::Print(GVJ_t* job, unsigned int id, bool isDefault) const
{
gvprintf(job, "<Hyperlink ID='%d'>\n", id);
if (_description)
gvprintf(job, "<Description>%s</Description>\n", _description);
if (_address)
gvprintf(job, "<Address>%s</Address>\n", _address);
if (_frame)
gvprintf(job, "<Frame>%s</Frame>\n", _frame);
if (isDefault)
gvputs(job, "<Default>1</Default>\n");
gvputs(job, "</Hyperlink>\n");
}
}
|