#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 "RefPtrCairo.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 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,
fontSmoothingMode);
}
Path Font::platformPathForGlyph(Glyph glyph) const
{
RefPtr<cairo_t> cr = adoptRef(cairo_create(adoptRef(cairo_image_surface_create(CAIRO_FORMAT_A8, 1, 1)).get()));
cairo_glyph_t cairoGlyph = { glyph, 0, 0 };
cairo_set_scaled_font(cr.get(), platformData().scaledFont());
cairo_glyph_path(cr.get(), &cairoGlyph, 1);
float syntheticBoldOffset = this->syntheticBoldOffset();
if (syntheticBoldOffset) {
cairo_translate(cr.get(), syntheticBoldOffset, 0);
cairo_glyph_path(cr.get(), &cairoGlyph, 1);
}
return Path(WTFMove(cr));
}
}
#endif // USE(CAIRO)