File: gr_Abi_RenderingContext.cpp

package info (click to toggle)
abiword 3.0.8%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 64,532 kB
  • sloc: cpp: 477,427; ansic: 16,754; makefile: 5,787; xml: 4,014; yacc: 1,818; lex: 1,104; perl: 812; python: 413; php: 183; sh: 169
file content (138 lines) | stat: -rw-r--r-- 4,256 bytes parent folder | download | duplicates (7)
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
/* AbiWord
 * Copyright (C) 2004 Luca Padovani <lpadovan@cs.unibo.it>
 *
 * 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.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301 USA.
 */

#include "gr_Graphics.h"
#include "gr_Painter.h"
#include "gr_Abi_RenderingContext.h"
#include <math.h>

GR_Abi_RenderingContext::GR_Abi_RenderingContext(GR_Graphics* pGr)
  : m_pGraphics(pGr)
{
  UT_ASSERT(m_pGraphics);
}

GR_Abi_RenderingContext::~GR_Abi_RenderingContext()
{ }

void
GR_Abi_RenderingContext::setColor(const UT_RGBColor& c)
{ m_pGraphics->setColor(c); }

void
GR_Abi_RenderingContext::getColor(UT_RGBColor& c) const
{ m_pGraphics->getColor(c); }

void
GR_Abi_RenderingContext::getColor(RGBColor& c) const
{ 
  UT_RGBColor color;
  m_pGraphics->getColor(color);
  c = GR_Abi_RenderingContext::fromAbiColor(color);
}

 UT_sint32 GR_Abi_RenderingContext::toAbiLayoutUnits(const scaled& s) const
{
  return round(s * UT_LAYOUT_RESOLUTION / 72.0).toDouble();
}

scaled GR_Abi_RenderingContext::fromAbiLayoutUnits(UT_sint32 s)  const
{
  return scaled(s * 72.0 / UT_LAYOUT_RESOLUTION);
}

 scaled GR_Abi_RenderingContext::fromAbiX(UT_sint32 x) const
  { return fromAbiLayoutUnits(x); }

 scaled GR_Abi_RenderingContext::fromAbiY(UT_sint32 y)  const
  { return fromAbiLayoutUnits(-y); }


  UT_sint32 GR_Abi_RenderingContext::toAbiX(const scaled& x)  const
  { return toAbiLayoutUnits(x); }


  UT_sint32 GR_Abi_RenderingContext::toAbiY(const scaled& y)  const
  { return toAbiLayoutUnits(-y); }

void
GR_Abi_RenderingContext::fill(const UT_RGBColor& color, const scaled& x, const scaled& y, const BoundingBox& box) const
{
  xxx_UT_DEBUGMSG(("GR_Abi_RenderingContext::fill: color = %d %d %d at (%d,%d) box = [%d,%d,%d]\n",
		   color.m_red, color.m_grn, color.m_blu,
		   toAbiLayoutUnits(x), toAbiLayoutUnits(y),
		   toAbiLayoutUnits(box.width), toAbiLayoutUnits(box.height), toAbiLayoutUnits(box.depth)));
  GR_Painter Painter(m_pGraphics);
  UT_sint32 iHeight = toAbiLayoutUnits(box.verticalExtent());
  m_pGraphics->antiAliasAlways(true);
  UT_DEBUGMSG(("Doing Fill in Math iHeight %d \n",iHeight));
  Painter.fillRect(color,
		   toAbiX(x),
		   toAbiY(y + box.verticalExtent()),
		   toAbiLayoutUnits(box.horizontalExtent()),
		   iHeight);
  m_pGraphics->antiAliasAlways(false);
}

void
GR_Abi_RenderingContext::fill(const scaled& x, const scaled& y, const BoundingBox& box) const
{
  UT_RGBColor color;
  getColor(color);
  fill(color, x, y, box);
}

void
GR_Abi_RenderingContext::drawGlyph(const scaled& x, const scaled& y, GR_Font* f, UT_uint32 glyph) const
{
  m_pGraphics->setFont(f);
  GR_Painter Painter(m_pGraphics);
  Painter.drawGlyph(glyph,
		    toAbiX(x),
		    toAbiY(y));
}

void
GR_Abi_RenderingContext::drawChar(const scaled& x, const scaled& y, GR_Font* f, UT_UCS4Char c) const
{
  m_pGraphics->setFont(f);
  GR_Painter Painter(m_pGraphics);
  UT_sint32 ax = toAbiX(x);
  UT_sint32 ay = toAbiY(y) - m_pGraphics->getFontAscent(f);
  Painter.drawChars(&c, 0, 1,ax,ay);
}

void
GR_Abi_RenderingContext::drawBox(const scaled& x, const scaled& y, const BoundingBox& box) const
{
  UT_DEBUGMSG(("Doing drawBox in Math \n"));
  const UT_sint32 x0 = toAbiX(x);
  const UT_sint32 x1 = toAbiX(x + box.width);
  const UT_sint32 y0 = toAbiY(y);
  const UT_sint32 y1 = toAbiY(y + box.height);
  const UT_sint32 y2 = toAbiY(y - box.depth);
  GR_Painter Painter(m_pGraphics);
  m_pGraphics->antiAliasAlways(true);
  Painter.drawLine(x0, y0, x1, y0);
  Painter.drawLine(x0, y1, x0, y2);
  Painter.drawLine(x1, y1, x1, y2);
  Painter.drawLine(x0, y1, x1, y1);
  Painter.drawLine(x0, y2, x1, y2);
  m_pGraphics->antiAliasAlways(false);
}