#include "config.h"
#include "FontCascade.h"
#if USE(CAIRO)
#include "AffineTransform.h"
#include "CairoOperations.h"
#include "CairoUtilities.h"
#include "Font.h"
#include "GlyphBuffer.h"
#include "Gradient.h"
#include "GraphicsContext.h"
#include "ImageBuffer.h"
#include "Pattern.h"
#include "PlatformContextCairo.h"
#include "PlatformPathCairo.h"
#include "ShadowBlur.h"
namespace WebCore {
void FontCascade::drawGlyphs(GraphicsContext& context, const Font& font, const GlyphBuffer& glyphBuffer,
unsigned from, unsigned numGlyphs, const FloatPoint& point, FontSmoothingMode)
{
if (!font.platformData().size())
return;
auto xOffset = point.x();
Vector<cairo_glyph_t> glyphs(numGlyphs);
{
ASSERT(from + numGlyphs <= glyphBuffer.size());
auto* glyphsData = glyphBuffer.glyphs(from);
auto* advances = glyphBuffer.advances(from);
auto yOffset = point.y();
for (size_t i = 0; i < numGlyphs; ++i) {
glyphs[i] = { glyphsData[i], xOffset, yOffset };
xOffset += advances[i].width();
yOffset -= advances[i].height();
}
}
cairo_scaled_font_t* scaledFont = font.platformData().scaledFont();
double syntheticBoldOffset = font.syntheticBoldOffset();
ASSERT(context.hasPlatformContext());
auto& state = context.state();
Cairo::drawGlyphs(*context.platformContext(), Cairo::FillSource(state), Cairo::StrokeSource(state),
Cairo::ShadowState(state), point, scaledFont, syntheticBoldOffset, glyphs, xOffset,
state.textDrawingMode, state.strokeThickness, state.shadowOffset, state.shadowColor);
}
Path Font::platformPathForGlyph(Glyph glyph) const
{
Path path;
path.ensurePlatformPath();
cairo_glyph_t cairoGlyph = { glyph, 0, 0 };
cairo_set_scaled_font(path.platformPath()->context(), platformData().scaledFont());
cairo_glyph_path(path.platformPath()->context(), &cairoGlyph, 1);
float syntheticBoldOffset = this->syntheticBoldOffset();
if (syntheticBoldOffset) {
cairo_translate(path.platformPath()->context(), syntheticBoldOffset, 0);
cairo_glyph_path(path.platformPath()->context(), &cairoGlyph, 1);
}
return path;
}
}
#endif // USE(CAIRO)