本文整理汇总了C++中GlyphBuffer::advanceAt方法的典型用法代码示例。如果您正苦于以下问题:C++ GlyphBuffer::advanceAt方法的具体用法?C++ GlyphBuffer::advanceAt怎么用?C++ GlyphBuffer::advanceAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GlyphBuffer
的用法示例。
在下文中一共展示了GlyphBuffer::advanceAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getGlyphsAndAdvancesForSimpleText
float Font::getGlyphsAndAdvancesForSimpleText(const TextRun& run, int from, int to, GlyphBuffer& glyphBuffer, ForTextEmphasisOrNot forTextEmphasis) const
{
WidthIterator it(this, run, 0, false, forTextEmphasis);
GlyphBuffer localGlyphBuffer;
it.advance(run.length(), &localGlyphBuffer);
if (localGlyphBuffer.isEmpty())
return 0;
float totalWidth = it.m_runWidthSoFar;
float beforeWidth = 0;
int glyphPos = 0;
for (; glyphPos < localGlyphBuffer.size() && it.m_characterIndexOfGlyph[glyphPos] < from; ++glyphPos)
beforeWidth += localGlyphBuffer.advanceAt(glyphPos).width();
int glyphFrom = glyphPos;
float afterWidth = totalWidth;
glyphPos = localGlyphBuffer.size() - 1;
for (; glyphPos >= glyphFrom && it.m_characterIndexOfGlyph[glyphPos] >= to; --glyphPos)
afterWidth -= localGlyphBuffer.advanceAt(glyphPos).width();
int glyphTo = glyphPos + 1;
glyphBuffer.add(&localGlyphBuffer, glyphFrom, glyphTo - glyphFrom);
if (run.rtl()) {
glyphBuffer.reverse(0, glyphBuffer.size());
return totalWidth - afterWidth;
}
return beforeWidth;
}
示例2: selectionRectForSimpleText
FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& point, int h, int from, int to) const
{
GlyphBuffer glyphBuffer;
WidthIterator it(this, run);
it.advance(run.length(), &glyphBuffer);
float totalWidth = it.m_runWidthSoFar;
float beforeWidth = 0;
int glyphPos = 0;
for (; glyphPos < glyphBuffer.size() && it.m_characterIndexOfGlyph[glyphPos] < from; ++glyphPos)
beforeWidth += glyphBuffer.advanceAt(glyphPos).width();
int glyphFrom = glyphPos;
float afterWidth = totalWidth;
glyphPos = glyphBuffer.size() - 1;
for (; glyphPos >= glyphFrom && it.m_characterIndexOfGlyph[glyphPos] >= to; --glyphPos)
afterWidth -= glyphBuffer.advanceAt(glyphPos).width();
// Using roundf() rather than ceilf() for the right edge as a compromise to ensure correct caret positioning.
if (run.rtl()) {
return FloatRect(floorf(point.x() + totalWidth - afterWidth), point.y(), roundf(point.x() + totalWidth - beforeWidth) - floorf(point.x() + totalWidth - afterWidth), h);
}
return FloatRect(floorf(point.x() + beforeWidth), point.y(), roundf(point.x() + afterWidth) - floorf(point.x() + beforeWidth), h);
}
示例3: drawGlyphBuffer
void Font::drawGlyphBuffer(GraphicsContext* context, const TextRun& run, const GlyphBuffer& glyphBuffer, FloatPoint& point) const
{
#if !ENABLE(SVG_FONTS)
UNUSED_PARAM(run);
#endif
// Draw each contiguous run of glyphs that use the same font data.
const SimpleFontData* fontData = glyphBuffer.fontDataAt(0);
FloatSize offset = glyphBuffer.offsetAt(0);
FloatPoint startPoint(point.x(), point.y() - glyphBuffer.initialAdvance().height());
float nextX = startPoint.x() + glyphBuffer.advanceAt(0).width();
float nextY = startPoint.y() + glyphBuffer.advanceAt(0).height();
int lastFrom = 0;
int nextGlyph = 1;
#if ENABLE(SVG_FONTS)
TextRun::RenderingContext* renderingContext = run.renderingContext();
#endif
while (nextGlyph < glyphBuffer.size()) {
const SimpleFontData* nextFontData = glyphBuffer.fontDataAt(nextGlyph);
FloatSize nextOffset = glyphBuffer.offsetAt(nextGlyph);
if (nextFontData != fontData || nextOffset != offset) {
#if ENABLE(SVG_FONTS)
if (renderingContext && fontData->isSVGFont())
renderingContext->drawSVGGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
else
#endif
drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
lastFrom = nextGlyph;
fontData = nextFontData;
offset = nextOffset;
startPoint.setX(nextX);
startPoint.setY(nextY);
}
nextX += glyphBuffer.advanceAt(nextGlyph).width();
nextY += glyphBuffer.advanceAt(nextGlyph).height();
nextGlyph++;
}
#if ENABLE(SVG_FONTS)
if (renderingContext && fontData->isSVGFont())
renderingContext->drawSVGGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
else {
#endif
drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
point.setX(nextX);
#if ENABLE(SVG_FONTS)
}
#endif
}
示例4: drawGlyphs
void Font::drawGlyphs(GraphicsContext* graphicsContext, const FontData* font, const GlyphBuffer& glyphBuffer,
int from, int numGlyphs, const FloatPoint& point) const
{
cairo_t* context = graphicsContext->platformContext();
// Set the text color to use for drawing.
float red, green, blue, alpha;
Color penColor = graphicsContext->pen().color();
penColor.getRGBA(red, green, blue, alpha);
cairo_set_source_rgba(context, red, green, blue, alpha);
// Select the scaled font.
font->setFont(context);
GlyphBufferGlyph* glyphs = glyphBuffer.glyphs(from);
float offset = point.x();
for (unsigned i = 0; i < numGlyphs; i++) {
glyphs[i].x = offset;
glyphs[i].y = point.y();
offset += glyphBuffer.advanceAt(from + i);
}
cairo_show_glyphs(context, glyphs, numGlyphs);
}
示例5: drawTextWithSpacing
void drawTextWithSpacing(GraphicsContext* graphicsContext, const SimpleFontData* font, const wxColour& color, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point)
{
#if USE(WXGC)
wxGCDC* dc = static_cast<wxGCDC*>(graphicsContext->platformContext());
#else
wxDC* dc = graphicsContext->platformContext();
#endif
wxFont* wxfont = font->getWxFont();
if (wxfont->IsOk())
dc->SetFont(*wxfont);
dc->SetTextForeground(color);
// convert glyphs to wxString
GlyphBufferGlyph* glyphs = const_cast<GlyphBufferGlyph*>(glyphBuffer.glyphs(from));
int offset = point.x();
wxString text = wxEmptyString;
for (unsigned i = 0; i < numGlyphs; i++) {
text = text.Append((wxChar)glyphs[i]);
offset += glyphBuffer.advanceAt(from + i);
}
// NOTE: The wx API actually adds the ascent to the y value internally,
// so we have to subtract it from the y point here so that the ascent
// isn't added twice.
dc->DrawText(text, (wxCoord)point.x(), int(point.y() - font->ascent()));
}
示例6: drawGlyphs
void Font::drawGlyphs(GraphicsContext* graphicsContext, const FontData* font, const GlyphBuffer& glyphBuffer,
int from, int numGlyphs, const FloatPoint& point) const
{
cairo_t* context = graphicsContext->platformContext();
// Set the text color to use for drawing.
float red, green, blue, alpha;
Color penColor = graphicsContext->fillColor();
penColor.getRGBA(red, green, blue, alpha);
cairo_set_source_rgba(context, red, green, blue, alpha);
// This was commented out as it made "some text invisible" but seems to work now.
font->setFont(context);
GlyphBufferGlyph* glyphs = (GlyphBufferGlyph*) glyphBuffer.glyphs(from);
float offset = point.x();
for (int i = 0; i < numGlyphs; i++) {
glyphs[i].x = offset;
glyphs[i].y = point.y();
offset += glyphBuffer.advanceAt(from + i);
}
cairo_show_glyphs(context, glyphs, numGlyphs);
}
示例7: drawTextWithSpacing
void drawTextWithSpacing(GraphicsContext* graphicsContext, const SimpleFontData* font, const wxColour& color, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point)
{
#if USE(WXGC)
wxGCDC* dc = static_cast<wxGCDC*>(graphicsContext->platformContext());
#else
wxDC* dc = graphicsContext->platformContext();
#endif
wxFont wxfont = font->getWxFont();
if (wxfont.IsOk())
dc->SetFont(wxfont);
dc->SetTextForeground(color);
// convert glyphs to wxString
GlyphBufferGlyph* glyphs = const_cast<GlyphBufferGlyph*>(glyphBuffer.glyphs(from));
int offset = point.x();
wxString text = wxEmptyString;
for (unsigned i = 0; i < numGlyphs; i++) {
text = text.Append((wxChar)glyphs[i]);
offset += glyphBuffer.advanceAt(from + i);
}
// the y point is actually the bottom point of the text, turn it into the top
float height = font->ascent() - font->descent();
wxCoord ypoint = (wxCoord) (point.y() - height);
dc->DrawText(text, (wxCoord)point.x(), ypoint);
}
示例8: drawEmphasisMarks
void Font::drawEmphasisMarks(GraphicsContext* context, const TextRun& run, const GlyphBuffer& glyphBuffer, const AtomicString& mark, const FloatPoint& point) const
{
FontCachePurgePreventer purgePreventer;
GlyphData markGlyphData;
if (!getEmphasisMarkGlyphData(mark, markGlyphData))
return;
const SimpleFontData* markFontData = markGlyphData.fontData;
ASSERT(markFontData);
if (!markFontData)
return;
Glyph markGlyph = markGlyphData.glyph;
Glyph spaceGlyph = markFontData->spaceGlyph();
float middleOfLastGlyph = offsetToMiddleOfGlyphAtIndex(glyphBuffer, 0);
FloatPoint startPoint(point.x() + middleOfLastGlyph - offsetToMiddleOfGlyph(markFontData, markGlyph), point.y());
GlyphBuffer markBuffer;
for (int i = 0; i + 1 < glyphBuffer.size(); ++i) {
float middleOfNextGlyph = offsetToMiddleOfGlyphAtIndex(glyphBuffer, i + 1);
float advance = glyphBuffer.advanceAt(i).width() - middleOfLastGlyph + middleOfNextGlyph;
markBuffer.add(glyphBuffer.glyphAt(i) ? markGlyph : spaceGlyph, markFontData, advance);
middleOfLastGlyph = middleOfNextGlyph;
}
markBuffer.add(glyphBuffer.glyphAt(glyphBuffer.size() - 1) ? markGlyph : spaceGlyph, markFontData, 0);
drawGlyphBuffer(context, run, markBuffer, startPoint);
}
示例9: offsetForPositionForSimpleText
int Font::offsetForPositionForSimpleText(const TextRun& run, float x, bool includePartialGlyphs) const
{
GlyphBuffer glyphBuffer;
WidthIterator it(this, run);
it.advance(run.length(), &glyphBuffer);
int characterOffset = 0;
if (run.rtl()) {
float currentX = it.m_runWidthSoFar;
for (int glyphPosition = 0; glyphPosition <= glyphBuffer.size(); ++glyphPosition) {
if (glyphPosition == glyphBuffer.size()) {
characterOffset = run.length();
break;
}
characterOffset = it.m_characterIndexOfGlyph[glyphPosition];
float glyphWidth = glyphBuffer.advanceAt(glyphPosition).width();
if (includePartialGlyphs) {
if (currentX - glyphWidth / 2.0f <= x)
break;
} else {
if (currentX - glyphWidth <= x)
break;
}
currentX -= glyphWidth;
}
} else {
float currentX = 0;
for (int glyphPosition = 0; glyphPosition <= glyphBuffer.size(); ++glyphPosition) {
if (glyphPosition == glyphBuffer.size()) {
characterOffset = run.length();
break;
}
characterOffset = it.m_characterIndexOfGlyph[glyphPosition];
float glyphWidth = glyphBuffer.advanceAt(glyphPosition).width();
if (includePartialGlyphs) {
if (currentX + glyphWidth / 2.0f >= x)
break;
} else {
if (currentX + glyphWidth >= x)
break;
}
currentX += glyphWidth;
}
}
return characterOffset;
}
示例10: advanceOneCharacter
bool WidthIterator::advanceOneCharacter(float& width, GlyphBuffer& glyphBuffer)
{
int oldSize = glyphBuffer.size();
advance(m_currentCharacter + 1, &glyphBuffer);
float w = 0;
for (int i = oldSize; i < glyphBuffer.size(); ++i)
w += glyphBuffer.advanceAt(i);
width = w;
return glyphBuffer.size() > oldSize;
}
示例11: drawGlyphBuffer
void Font::drawGlyphBuffer(GraphicsContext* context, const TextRunPaintInfo& runInfo, const GlyphBuffer& glyphBuffer, const FloatPoint& point) const
{
// Draw each contiguous run of glyphs that use the same font data.
const SimpleFontData* fontData = glyphBuffer.fontDataAt(0);
FloatPoint startPoint(point);
float nextX = startPoint.x() + glyphBuffer.advanceAt(0);
unsigned lastFrom = 0;
unsigned nextGlyph = 1;
#if ENABLE(SVG_FONTS)
TextRun::RenderingContext* renderingContext = runInfo.run.renderingContext();
#endif
while (nextGlyph < glyphBuffer.size()) {
const SimpleFontData* nextFontData = glyphBuffer.fontDataAt(nextGlyph);
if (nextFontData != fontData) {
#if ENABLE(SVG_FONTS)
if (renderingContext && fontData->isSVGFont())
renderingContext->drawSVGGlyphs(context, runInfo.run, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
else
#endif
drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint, runInfo.bounds);
lastFrom = nextGlyph;
fontData = nextFontData;
startPoint.setX(nextX);
}
nextX += glyphBuffer.advanceAt(nextGlyph);
nextGlyph++;
}
#if ENABLE(SVG_FONTS)
if (renderingContext && fontData->isSVGFont())
renderingContext->drawSVGGlyphs(context, runInfo.run, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint);
else
#endif
drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint, runInfo.bounds);
}
示例12: drawGlyphs
void Font::drawGlyphs(GraphicsContext* graphicsContext, const SimpleFontData* sfont, const GlyphBuffer& glyphBuffer,
int from, int numGlyphs, const FloatPoint& point) const
{
int i = 0;
FloatPoint pos(point);
float w=0, h=0;
UChar c=0;
void* dc = (void *)graphicsContext->platformContext();
WKCPeerFont pf;
WKCFloatRect clip;
WKCFloatPoint pp;
if (!dc) return;
pf.fFont = sfont->platformData().Font();
if (!pf.fFont) return;
const FontPlatformData& pd(sfont->platformData());
pf.fRequestedSize = pd.requestSize();
pf.fCreatedSize = pd.createdSize();
pf.fWeight = pd.weight();
pf.fItalic = pd.isItalic();
pf.fScale = pd.scale();
pf.fiScale = pd.iscale();
pf.fCanScale = pd.canScale();
pf.fFontId = (void *)pd.hash();
pos.setY(pos.y() - (float)pd.ascent()*pd.scale());
h = (pd.lineSpacing()) * pd.scale();
for (i=0; i<numGlyphs; i++) {
float advance = 0.f;
c = fixedChar(glyphBuffer.glyphAt(from + i));
if (!c) continue;
advance = glyphBuffer.advanceAt(from + i);
w = wkcFontGetClipWidthPeer(pf.fFont, c) * pd.scale();
clip.fX = pos.x();
clip.fY = pos.y();
clip.fWidth = w;
clip.fHeight = h;
pp.fX = pos.x();
pp.fY = pos.y();
wkcDrawContextDrawCharPeer(dc, (unsigned int)c, &pp, &clip, &pf);
pos.move(advance, 0);
}
}
示例13: drawGlyphs
void Font::drawGlyphs(GraphicsContext* context, const SimpleFontData* fontData, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) const
{
if (context->paintingDisabled())
return;
bool shouldFill = context->textDrawingMode() & TextModeFill;
bool shouldStroke = context->textDrawingMode() & TextModeStroke;
// Stroking text should always take the complex path.
ASSERT(!shouldStroke);
// Shadowed text should always take the complex path.
ASSERT(context->contextShadow()->m_type == ContextShadow::NoShadow);
if (!shouldFill && !shouldStroke)
return;
QVector<quint32> glyphIndexes;
QVector<QPointF> positions;
glyphIndexes.reserve(numGlyphs);
positions.reserve(numGlyphs);
float x = 0;
for (int i = 0; i < numGlyphs; ++i) {
Glyph glyph = glyphBuffer.glyphAt(from + i);
float advance = glyphBuffer.advanceAt(from + i);
if (!glyph)
continue;
glyphIndexes.append(glyph);
positions.append(QPointF(x, 0));
x += advance;
}
QGlyphs qtGlyphs;
qtGlyphs.setGlyphIndexes(glyphIndexes);
qtGlyphs.setPositions(positions);
qtGlyphs.setFont(fontData->platformData().rawFont());
QPainter* painter = context->platformContext();
QPen previousPen = painter->pen();
painter->setPen(fillPenForContext(context));
painter->drawGlyphs(point, qtGlyphs);
painter->setPen(previousPen);
}
示例14: drawGlyphs
void Font::drawGlyphs(GraphicsContext* context, const SimpleFontData* font, const GlyphBuffer& glyphBuffer,
int from, int numGlyphs, const FloatPoint& point) const
{
if (!font->platformData().size())
return;
GlyphBufferGlyph* glyphs = const_cast<GlyphBufferGlyph*>(glyphBuffer.glyphs(from));
float offset = point.x();
for (int i = 0; i < numGlyphs; i++) {
glyphs[i].x = offset;
glyphs[i].y = point.y();
offset += glyphBuffer.advanceAt(from + i).width();
}
PlatformContextCairo* platformContext = context->platformContext();
drawGlyphsShadow(context, point, font, glyphs, numGlyphs);
cairo_t* cr = platformContext->cr();
cairo_save(cr);
if (context->textDrawingMode() & TextModeFill) {
platformContext->prepareForFilling(context->state(), PlatformContextCairo::AdjustPatternForGlobalAlpha);
drawGlyphsToContext(cr, font, glyphs, numGlyphs);
}
// Prevent running into a long computation within cairo. If the stroke width is
// twice the size of the width of the text we will not ask cairo to stroke
// the text as even one single stroke would cover the full wdth of the text.
// See https://bugs.webkit.org/show_bug.cgi?id=33759.
if (context->textDrawingMode() & TextModeStroke && context->strokeThickness() < 2 * offset) {
platformContext->prepareForStroking(context->state());
cairo_set_line_width(cr, context->strokeThickness());
// This may disturb the CTM, but we are going to call cairo_restore soon after.
cairo_set_scaled_font(cr, font->platformData().scaledFont());
cairo_glyph_path(cr, glyphs, numGlyphs);
cairo_stroke(cr);
}
cairo_restore(cr);
}
示例15: drawSVGGlyphs
void SVGTextRunRenderingContext::drawSVGGlyphs(GraphicsContext* context, const TextRun& run, const SimpleFontData* fontData, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) const
{
SVGFontElement* fontElement = 0;
SVGFontFaceElement* fontFaceElement = 0;
const SVGFontData* svgFontData = svgFontAndFontFaceElementForFontData(fontData, fontFaceElement, fontElement);
if (!fontElement || !fontFaceElement)
return;
// We can only paint SVGFonts if a context is available.
RenderObject* renderObject = renderObjectFromRun(run);
ASSERT(renderObject);
bool isVerticalText = false;
if (RenderObject* parentRenderObject = firstParentRendererForNonTextNode(renderObject)) {
RenderStyle* parentRenderObjectStyle = parentRenderObject->style();
ASSERT(parentRenderObjectStyle);
isVerticalText = parentRenderObjectStyle->svgStyle().isVerticalWritingMode();
}
float scale = scaleEmToUnits(fontData->platformData().size(), fontFaceElement->unitsPerEm());
FloatPoint glyphOrigin;
glyphOrigin.setX(svgFontData->horizontalOriginX() * scale);
glyphOrigin.setY(svgFontData->horizontalOriginY() * scale);
unsigned short resourceMode = context->textDrawingMode() == TextModeStroke ? ApplyToStrokeMode : ApplyToFillMode;
FloatPoint currentPoint = point;
for (int i = 0; i < numGlyphs; ++i) {
Glyph glyph = glyphBuffer.glyphAt(from + i);
if (!glyph)
continue;
float advance = glyphBuffer.advanceAt(from + i);
SVGGlyph svgGlyph = fontElement->svgGlyphForGlyph(glyph);
ASSERT(!svgGlyph.isPartOfLigature);
ASSERT(svgGlyph.tableEntry == glyph);
SVGGlyphElement::inheritUnspecifiedAttributes(svgGlyph, svgFontData);
// FIXME: Support arbitary SVG content as glyph (currently limited to <glyph d="..."> situations).
if (svgGlyph.pathData.isEmpty()) {
if (isVerticalText)
currentPoint.move(0, advance);
else
currentPoint.move(advance, 0);
continue;
}
if (isVerticalText) {
glyphOrigin.setX(svgGlyph.verticalOriginX * scale);
glyphOrigin.setY(svgGlyph.verticalOriginY * scale);
}
AffineTransform glyphPathTransform;
glyphPathTransform.translate(currentPoint.x() + glyphOrigin.x(), currentPoint.y() + glyphOrigin.y());
glyphPathTransform.scale(scale, -scale);
Path glyphPath = svgGlyph.pathData;
glyphPath.transform(glyphPathTransform);
SVGRenderSupport::fillOrStrokePath(context, resourceMode, glyphPath);
if (isVerticalText)
currentPoint.move(0, advance);
else
currentPoint.move(advance, 0);
}
}