15 #include "pnmTextGlyph.h"
24 PNMTextGlyph(
double advance) :
29 _int_advance = (int)floor(_advance + 0.5);
58 int left = xp + _left;
64 int cleft = max(left, 0);
65 int ctop = max(top, 0);
66 int cright = min(right, dest_image.
get_x_size());
67 int cbottom = min(bottom, dest_image.
get_y_size());
69 for (
int y = ctop; y < cbottom; y++) {
70 for (
int x = cleft; x < cright; x++) {
71 double gval =
get_value(x - left, y - top);
75 }
else if (gval > 0.0) {
77 dest_image.
set_xel_a(x, y, fg * gval + bg * (1.0 - gval));
98 int left = xp + _left;
104 int cleft = max(left, 0);
105 int ctop = max(top, 0);
106 int cright = min(right, dest_image.
get_x_size());
107 int cbottom = min(bottom, dest_image.
get_y_size());
109 for (
int y = ctop; y < cbottom; y++) {
110 for (
int x = cleft; x < cright; x++) {
111 double gval =
get_value(x - left, y - top);
115 }
else if (gval > 0.0) {
124 dest_image.
set_xel_a(x, y, fg * gval + bg * (1.0 - gval));
145 determine_interior() {
151 for (
int yi = 0; yi < y_size; yi++) {
152 for (
int xi = 0; xi < x_size; xi++) {
162 _scan_interior_points.clear();
163 for (
int yi = 0; yi < y_size; yi++) {
164 scan_interior(0, yi, 0,
false, 0);
165 scan_interior(x_size - 1, yi, 0,
false, 0);
167 for (
int xi = 0; xi < x_size; xi++) {
168 scan_interior(xi, 0, 0,
false, 0);
169 scan_interior(xi, y_size - 1, 0,
false, 0);
174 while (!_scan_interior_points.empty()) {
175 int index = _scan_interior_points.back();
176 _scan_interior_points.pop_back();
182 scan_interior(x - 1, y, new_code, this_dark, 0);
183 scan_interior(x, y - 1, new_code, this_dark, 0);
184 scan_interior(x + 1, y, new_code, this_dark, 0);
185 scan_interior(x, y + 1, new_code, this_dark, 0);
187 _scan_interior_points.clear();
192 for (
int yi = 0; yi < y_size; yi++) {
193 for (
int xi = 0; xi < x_size; xi++) {
195 if (((code + 2) & 0x3) == 0) {
213 scan_interior(
int x,
int y, xelval new_code,
bool neighbor_dark,
219 if (this_dark != neighbor_dark) {
224 nassertv(new_code > 0);
230 if (recurse_level > 1024) {
236 _scan_interior_points.push_back(index);
239 scan_interior(x - 1, y, new_code, this_dark, recurse_level);
240 scan_interior(x, y - 1, new_code, this_dark, recurse_level);
241 scan_interior(x + 1, y, new_code, this_dark, recurse_level);
242 scan_interior(x, y + 1, new_code, this_dark, recurse_level);
254 rescale(
double scale_factor) {
255 if (scale_factor == 1.0) {
258 nassertv(scale_factor != 0.0);
259 _advance /= scale_factor;
260 _int_advance = (int)floor(_advance + 0.5);
265 int orig_left = _left;
270 int extra_pad = (int)ceil(scale_factor);
271 orig_x_size += 2*extra_pad;
272 orig_y_size += 2*extra_pad;
273 orig_left -= extra_pad;
274 orig_top += extra_pad;
277 int new_x_size = (int)ceil(orig_x_size / scale_factor);
278 int new_y_size = (int)ceil(orig_y_size / scale_factor);
279 int new_left = (int)floor(orig_left / scale_factor);
280 int new_top = (int)ceil(orig_top / scale_factor);
285 int old_x_size = (int)(new_x_size * scale_factor + 0.5);
286 int old_y_size = (int)(new_y_size * scale_factor + 0.5);
287 int old_left = (int)(new_left * scale_factor + 0.5);
288 int old_top = (int)(new_top * scale_factor + 0.5);
290 int pad_left = orig_left - old_left;
291 int pad_top = old_top - orig_top;
294 nassertv(extra_pad + pad_left >= 0 && extra_pad + pad_top >= 0);
297 enlarged.
copy_sub_image(_image, pad_left + extra_pad, pad_top + extra_pad);
double get_value(int x, int y) const
Returns the value of the indicated pixel of the glyph.
void copy_sub_image(const PNMImage ©, int xto, int yto, int xfrom=0, int yfrom=0, int x_size=-1, int y_size=-1)
Copies a rectangular area of another image into a rectangular area of this image. ...
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
bool is_valid() const
Returns true if the image has been read in or correctly initialized with a height and width...
LColorf get_xel_a(int x, int y) const
Returns the RGBA color at the indicated pixel.
xelval get_blue_val(int x, int y) const
Returns the blue component color at the indicated pixel.
bool get_interior_flag(int x, int y) const
Returns true if the indicated pixel represents a pixel in the interior of a hollow font...
void quick_filter_from(const PNMImage ©, int xborder=0, int yborder=0)
Resizes from the given image, with a fixed radius of 0.5.
void place(PNMImage &dest_image, int xp, int yp, const LColor &fg)
Copies the glyph to the indicated destination image at the indicated origin.
void set_xel_a(int x, int y, const LColorf &value)
Changes the RGBA color at the indicated pixel.
This is the base class for all three-component vectors and points.
void set_red_val(int x, int y, xelval r)
Sets the red component color only at the indicated pixel.
void clear()
Frees all memory allocated for the image, and clears all its parameters (size, color, type, etc).
xelval get_red_val(int x, int y) const
Returns the red component color at the indicated pixel.