int Font::offsetForPositionForSimpleText(const TextRun& run, int x, bool includePartialGlyphs) const { float delta = (float)x; WidthIterator it(this, run); GlyphBuffer localGlyphBuffer; unsigned offset; if (run.rtl()) { delta -= floatWidthForSimpleText(run, 0); while (1) { offset = it.m_currentCharacter; float w; if (!it.advanceOneCharacter(w, &localGlyphBuffer)) break; delta += w; if (includePartialGlyphs) { if (delta - w / 2 >= 0) break; } else { if (delta >= 0) break; } } } else { while (1) { offset = it.m_currentCharacter; float w; if (!it.advanceOneCharacter(w, &localGlyphBuffer)) break; delta -= w; if (includePartialGlyphs) { if (delta + w / 2 <= 0) break; } else { if (delta <= 0) break; } } } return offset; }
float Font::width(const TextRun& run, int extraCharsAvailable, int& charsConsumed, String& glyphName) const { #if !ENABLE(SVG_FONTS) UNUSED_PARAM(extraCharsAvailable); #else if (primaryFont()->isSVGFont()) return floatWidthUsingSVGFont(run, extraCharsAvailable, charsConsumed, glyphName); #endif charsConsumed = run.length(); glyphName = ""; #if USE(WRATH) //return DrawnTextOfWRATH::width(*this, run); #endif if (codePath(run) != Complex) return floatWidthForSimpleText(run, 0); return floatWidthForComplexText(run); }
float Font::width(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow* glyphOverflow) const { #if ENABLE(SVG_FONTS) if (primaryFont()->isSVGFont()) return floatWidthUsingSVGFont(run); #endif CodePath codePathToUse = codePath(run); if (codePathToUse != Complex) { // If the complex text implementation cannot return fallback fonts, avoid // returning them for simple text as well. static bool returnFallbackFonts = canReturnFallbackFontsForComplexText(); return floatWidthForSimpleText(run, 0, returnFallbackFonts ? fallbackFonts : 0, codePathToUse == SimpleWithGlyphOverflow || (glyphOverflow && glyphOverflow->computeBounds) ? glyphOverflow : 0); } #if USE(WRATH) // return DrawnTextOfWRATH::width(*this, run); #endif return floatWidthForComplexText(run, fallbackFonts, glyphOverflow); }
float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFontData*>* fallbackFonts, GlyphOverflow* overflow) const { #if USE(FREETYPE) if (!primaryFont()->platformData().m_pattern) return floatWidthForSimpleText(run, 0, fallbackFonts, overflow); #endif if (!run.length()) return 0.0f; PangoLayout* layout = getDefaultPangoLayout(run); setPangoAttributes(this, run, layout); gchar* utf8 = convertUniCharToUTF8(run.characters(), run.length(), 0, run.length()); pango_layout_set_text(layout, utf8, -1); int width; pango_layout_get_pixel_size(layout, &width, 0); g_free(utf8); g_object_unref(layout); return width; }