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
|
// -*- related-file-name: "../include/efont/t1bounds.hh" -*-
/* t1bounds.{cc,hh} -- charstring bounding box finder
*
* Copyright (c) 1998-2011 Eddie Kohler
*
* This program 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. This program 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.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <efont/t1bounds.hh>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
namespace Efont {
CharstringBounds::CharstringBounds()
: _lb(UNKDOUBLE, UNKDOUBLE), _rt(UNKDOUBLE, UNKDOUBLE),
_last_xf_program(0)
{
}
CharstringBounds::CharstringBounds(const Transform &nonfont_xf)
: _lb(UNKDOUBLE, UNKDOUBLE), _rt(UNKDOUBLE, UNKDOUBLE),
_nonfont_xf(nonfont_xf), _last_xf_program(0)
{
}
CharstringBounds::CharstringBounds(const Transform &nonfont_xf, const Vector<double> &weight)
: CharstringInterp(weight),
_lb(UNKDOUBLE, UNKDOUBLE), _rt(UNKDOUBLE, UNKDOUBLE),
_nonfont_xf(nonfont_xf), _last_xf_program(0)
{
}
void
CharstringBounds::clear()
{
_lb = _rt = Point(UNKDOUBLE, UNKDOUBLE);
}
void
CharstringBounds::xf_mark(const Bezier &b)
{
Bezier b1, b2;
b.halve(b1, b2);
xf_mark(b1.point(3));
if (!xf_controls_inside(b1))
xf_mark(b1);
if (!xf_controls_inside(b2))
xf_mark(b2);
}
void
CharstringBounds::act_width(int, const Point &w)
{
_width = w;
}
void
CharstringBounds::act_line(int, const Point &p0, const Point &p1)
{
mark(p0);
mark(p1);
}
void
CharstringBounds::act_curve(int, const Point &p0, const Point &p1, const Point &p2, const Point &p3)
{
Point q0 = p0 * _xf;
Point q1 = p1 * _xf;
Point q2 = p2 * _xf;
Point q3 = p3 * _xf;
xf_mark(q0);
xf_mark(q3);
if (!xf_inside(q1) || !xf_inside(q2)) {
Bezier b(q0, q1, q2, q3);
xf_mark(b);
}
}
void
CharstringBounds::set_xf(const CharstringProgram *program)
{
if (_last_xf_program != program) {
_last_xf_program = program;
double matrix[6];
program->font_matrix(matrix);
Transform font_xf = Transform(matrix).scaled(1000);
font_xf.check_null(0.001);
_xf = _nonfont_xf * font_xf;
}
}
bool
CharstringBounds::char_bounds(const CharstringContext &g, bool shift)
{
set_xf(g.program);
CharstringInterp::interpret(g);
if (shift) {
_xf.translate(_width);
_nonfont_xf.translate(_width);
}
return error() >= 0;
}
void
CharstringBounds::translate(double dx, double dy)
{
_xf.translate(dx, dy);
_nonfont_xf.translate(dx, dy);
}
bool
CharstringBounds::output(int bb[4], int &width, bool use_cur_width) const
{
if (!KNOWN(_lb.x))
bb[0] = bb[1] = bb[2] = bb[3] = 0;
else {
bb[0] = (int) floor(_lb.x);
bb[1] = (int) floor(_lb.y);
bb[2] = (int) ceil(_rt.x);
bb[3] = (int) ceil(_rt.y);
}
Point p;
if (use_cur_width)
p = _width * _xf;
else
p = Point(0, 0) * _xf;
width = (int) ceil(p.x);
return error() >= 0;
}
bool
CharstringBounds::bounds(const Transform &transform, const CharstringContext &g, int bb[4], int &width)
{
CharstringBounds b(transform);
b.char_bounds(g, false);
return b.output(bb, width, true);
}
bool
CharstringBounds::bounds(const CharstringContext &g, int bb[4], int &width)
{
CharstringBounds b;
b.char_bounds(g, false);
return b.output(bb, width, true);
}
}
|