Hash :
99848cfa
Author :
Date :
2004-06-23T20:33:35
#143693, Sayamindu Dasgupta
Wed Jun 23 16:13:53 2004 Owen Taylor <otaylor@redhat.com>
#143693, Sayamindu Dasgupta
* pango/opentype/pango-ot-buffer.c (pango_ot_buffer_set_zero_width_marks) pango/opentype/pango-ot-private.h:
Allow setting for whether marks should be given zero width,
defaulting to FALSE.
* modules/arabic/arabic-fc.c (arabic_engine_shape): Turn
on zero-width-marks setting.
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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
/* Pango
* pango-ot-buffer.c: Buffer of glyphs for shaping/positioning
*
* Copyright (C) 2004 Red Hat Software
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "pango-ot-private.h"
#define PANGO_SCALE_26_6 (PANGO_SCALE / (1<<6))
#define PANGO_UNITS_26_6(d) (PANGO_SCALE_26_6 * (d))
PangoOTBuffer *
pango_ot_buffer_new (PangoFcFont *font)
{
/* We lock the font here immediately for the silly reason
* of getting the FT_Memory; otherwise we'd have to
* add a new operation to PangoFcFontmap; callers will
* probably already have the font locked, however,
* so there is little performance penalty.
*/
PangoOTBuffer *buffer = g_new (PangoOTBuffer, 1);
FT_Face face = pango_fc_font_lock_face (font);
if (otl_buffer_new (face->memory, &buffer->buffer) != FT_Err_Ok)
g_error ("Allocation of OTLBuffer failed");
buffer->font = g_object_ref (font);
buffer->applied_gpos = FALSE;
buffer->rtl = FALSE;
buffer->zero_width_marks = FALSE;
pango_fc_font_unlock_face (font);
return buffer;
}
void
pango_ot_buffer_destroy (PangoOTBuffer *buffer)
{
otl_buffer_free (buffer->buffer);
g_object_unref (buffer->font);
g_free (buffer);
}
void
pango_ot_buffer_clear (PangoOTBuffer *buffer)
{
otl_buffer_clear (buffer->buffer);
buffer->applied_gpos = FALSE;
}
void
pango_ot_buffer_add_glyph (PangoOTBuffer *buffer,
guint glyph_index,
guint properties,
guint cluster)
{
otl_buffer_add_glyph (buffer->buffer,
glyph_index, properties, cluster);
}
void
pango_ot_buffer_set_rtl (PangoOTBuffer *buffer,
gboolean rtl)
{
rtl = rtl != FALSE;
buffer->rtl = rtl;
}
/**
* pango_ot_buffer_set_zero_width_marks:
* @buffer: a #PangoOTBuffer
* @zero_width_marks: %TRUE if characters with a mark class should
* be forced to zero width.
*
* Sets whether characters with a mark class should be forced to zero width.
* This setting is needed for proper positioning of Arabic accents,
* but will produce incorrect results with standard OpenType indic
* fonts.
**/
void
pango_ot_buffer_set_zero_width_marks (PangoOTBuffer *buffer,
gboolean zero_width_marks)
{
buffer->zero_width_marks = zero_width_marks != FALSE;
}
void
pango_ot_buffer_get_glyphs (PangoOTBuffer *buffer,
PangoOTGlyph **glyphs,
int *n_glyphs)
{
if (glyphs)
*glyphs = (PangoOTGlyph *)buffer->buffer->in_string;
if (n_glyphs)
*n_glyphs = buffer->buffer->in_length;
}
static void
swap_range (PangoGlyphString *glyphs, int start, int end)
{
int i, j;
for (i = start, j = end - 1; i < j; i++, j--)
{
PangoGlyphInfo glyph_info;
gint log_cluster;
glyph_info = glyphs->glyphs[i];
glyphs->glyphs[i] = glyphs->glyphs[j];
glyphs->glyphs[j] = glyph_info;
log_cluster = glyphs->log_clusters[i];
glyphs->log_clusters[i] = glyphs->log_clusters[j];
glyphs->log_clusters[j] = log_cluster;
}
}
static void
apply_gpos_ltr (PangoGlyphString *glyphs,
OTL_Position positions)
{
int i;
for (i = 0; i < glyphs->num_glyphs; i++)
{
FT_Pos x_pos = positions[i].x_pos;
FT_Pos y_pos = positions[i].y_pos;
int back = i;
int j;
while (positions[back].back != 0)
{
back -= positions[back].back;
x_pos += positions[back].x_pos;
y_pos += positions[back].y_pos;
}
for (j = back; j < i; j++)
glyphs->glyphs[i].geometry.x_offset -= glyphs->glyphs[j].geometry.width;
glyphs->glyphs[i].geometry.x_offset += PANGO_UNITS_26_6(x_pos);
glyphs->glyphs[i].geometry.y_offset -= PANGO_UNITS_26_6(y_pos);
if (positions[i].new_advance)
glyphs->glyphs[i].geometry.width = PANGO_UNITS_26_6(positions[i].x_advance);
else
glyphs->glyphs[i].geometry.width += PANGO_UNITS_26_6(positions[i].x_advance);
}
}
static void
apply_gpos_rtl (PangoGlyphString *glyphs,
OTL_Position positions)
{
int i;
for (i = 0; i < glyphs->num_glyphs; i++)
{
int i_rev = glyphs->num_glyphs - i - 1;
int back_rev = i_rev;
int back;
FT_Pos x_pos = positions[i_rev].x_pos;
FT_Pos y_pos = positions[i_rev].y_pos;
int j;
while (positions[back_rev].back != 0)
{
back_rev -= positions[back_rev].back;
x_pos += positions[back_rev].x_pos;
y_pos += positions[back_rev].y_pos;
}
back = glyphs->num_glyphs - back_rev - 1;
for (j = i; j < back; j++)
glyphs->glyphs[i].geometry.x_offset += glyphs->glyphs[j].geometry.width;
glyphs->glyphs[i].geometry.x_offset += PANGO_UNITS_26_6(x_pos);
glyphs->glyphs[i].geometry.y_offset -= PANGO_UNITS_26_6(y_pos);
if (positions[i_rev].new_advance)
glyphs->glyphs[i].geometry.width = PANGO_UNITS_26_6(positions[i_rev].x_advance);
else
glyphs->glyphs[i].geometry.width += PANGO_UNITS_26_6(positions[i_rev].x_advance);
}
}
void
pango_ot_buffer_output (PangoOTBuffer *buffer,
PangoGlyphString *glyphs)
{
FT_Face face;
PangoOTInfo *info;
TTO_GDEF gdef = NULL;
int i;
int last_cluster;
face = pango_fc_font_lock_face (buffer->font);
g_assert (face);
/* Copy glyphs into output glyph string */
pango_glyph_string_set_size (glyphs, buffer->buffer->in_length);
last_cluster = -1;
for (i = 0; i < buffer->buffer->in_length; i++)
{
OTL_GlyphItem item = &buffer->buffer->in_string[i];
glyphs->glyphs[i].glyph = item->gindex;
glyphs->log_clusters[i] = item->cluster;
if (glyphs->log_clusters[i] != last_cluster)
glyphs->glyphs[i].attr.is_cluster_start = 1;
else
glyphs->glyphs[i].attr.is_cluster_start = 0;
last_cluster = glyphs->log_clusters[i];
}
info = pango_ot_info_get (face);
gdef = pango_ot_info_get_gdef (info);
/* Apply default positioning */
for (i = 0; i < glyphs->num_glyphs; i++)
{
if (glyphs->glyphs[i].glyph)
{
PangoRectangle logical_rect;
FT_UShort property;
if (buffer->zero_width_marks &&
gdef &&
TT_GDEF_Get_Glyph_Property (gdef, glyphs->glyphs[i].glyph, &property) == FT_Err_Ok &&
(property == TTO_MARK || (property & IGNORE_SPECIAL_MARKS) != 0))
{
glyphs->glyphs[i].geometry.width = 0;
}
else
{
pango_font_get_glyph_extents ((PangoFont *)buffer->font, glyphs->glyphs[i].glyph, NULL, &logical_rect);
glyphs->glyphs[i].geometry.width = logical_rect.width;
}
}
else
glyphs->glyphs[i].geometry.width = 0;
glyphs->glyphs[i].geometry.x_offset = 0;
glyphs->glyphs[i].geometry.y_offset = 0;
}
if (buffer->rtl)
{
/* Swap all glyphs */
swap_range (glyphs, 0, glyphs->num_glyphs);
}
if (buffer->applied_gpos)
{
if (buffer->rtl)
apply_gpos_rtl (glyphs, buffer->buffer->positions);
else
apply_gpos_ltr (glyphs, buffer->buffer->positions);
}
pango_fc_font_unlock_face (buffer->font);
}