void QSvgFont::draw(QPainter *p, const QPointF &point, const QString &str, qreal pixelSize, Qt::Alignment alignment) const { p->save(); p->translate(point); p->scale(pixelSize / m_unitsPerEm, -pixelSize / m_unitsPerEm); // Calculate the text width to be used for alignment int textWidth = 0; QString::const_iterator itr = str.constBegin(); for ( ; itr != str.constEnd(); ++itr) { QChar unicode = *itr; if (!m_glyphs.contains(*itr)) { unicode = 0; if (!m_glyphs.contains(unicode)) continue; } textWidth += static_cast<int>(m_glyphs[unicode].m_horizAdvX); } QPoint alignmentOffset(0, 0); if (alignment == Qt::AlignHCenter) { alignmentOffset.setX(-textWidth / 2); } else if (alignment == Qt::AlignRight) { alignmentOffset.setX(-textWidth); } p->translate(alignmentOffset); // since in SVG the embedded font ain't really a path // the outline has got to stay untransformed... qreal penWidth = p->pen().widthF(); penWidth /= (pixelSize/m_unitsPerEm); QPen pen = p->pen(); pen.setWidthF(penWidth); p->setPen(pen); itr = str.constBegin(); for ( ; itr != str.constEnd(); ++itr) { QChar unicode = *itr; if (!m_glyphs.contains(*itr)) { unicode = 0; if (!m_glyphs.contains(unicode)) continue; } p->drawPath(m_glyphs[unicode].m_path); p->translate(m_glyphs[unicode].m_horizAdvX, 0); } p->restore(); }
CodePointBreakIterator* CodePointBreakIterator::createBufferClone(void *stackBuffer, int32_t &bufferSize, UErrorCode &status) { if (U_FAILURE(status)) { return nullptr; } if (bufferSize <= 0) { bufferSize = sizeof(CodePointBreakIterator) + alignmentOffsetUp(0); return nullptr; } char *buf = static_cast<char*>(stackBuffer); uint32_t s = bufferSize; if (!stackBuffer) { s = 0; } if (alignmentOffset(stackBuffer) != 0) { uint32_t offsetUp = (uint32_t)alignmentOffsetUp(buf); s -= offsetUp; buf += offsetUp; } if (s < sizeof(CodePointBreakIterator)) { CodePointBreakIterator *clonedBI = new CodePointBreakIterator(*this); if (!clonedBI) { status = U_MEMORY_ALLOCATION_ERROR; } else { status = U_SAFECLONE_ALLOCATED_WARNING; } return clonedBI; } return new(buf) CodePointBreakIterator(*this); }
// TODO: Check whether this function should be moved into MapObject::bounds static void align(QRectF &r, Alignment alignment) { r.translate(-alignmentOffset(r, alignment)); }
inline size_t alignmentOffsetUp(void *ptr) { return sizeof(UAlignedMemory) - alignmentOffset(ptr); }