本文整理汇总了C++中QPainterPath::addText方法的典型用法代码示例。如果您正苦于以下问题:C++ QPainterPath::addText方法的具体用法?C++ QPainterPath::addText怎么用?C++ QPainterPath::addText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QPainterPath
的用法示例。
在下文中一共展示了QPainterPath::addText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintEvent
void QgsLabelPreview::paintEvent( QPaintEvent *e )
{
Q_UNUSED( e );
QPainter p( this );
// TODO: draw all label components when this preview is an actual map canvas
// for now, only preview label's text and buffer
mTmpLyr->shadowDraw = false;
p.setRenderHint( QPainter::Antialiasing );
p.setFont( font() );
QFontMetrics fm( font() );
// otherwise thin buffers don't look like those on canvas
if ( mTmpLyr->bufferSize != 0 && mTmpLyr->bufferSize < 1 )
mTmpLyr->bufferSize = 1;
double xtrans = 0;
if ( mTmpLyr->bufferSize != 0 )
xtrans = mTmpLyr->bufferSize / 4;
p.translate( xtrans, fm.ascent() + 4 );
if ( mTmpLyr->bufferSize != 0 )
{
mContext->setPainter( &p );
QgsLabelComponent component;
component.setText( text() );
QgsPalLabeling::drawLabelBuffer( *mContext, component, *mTmpLyr );
}
QPainterPath path;
path.addText( 0, 0, font(), text() );
p.setPen( Qt::NoPen );
p.setBrush( mTextColor );
p.drawPath( path );
// p.setPen( mTextColor );
// p.drawText( 0, 0, text() );
}
示例2: paint
void SimpleTextContent::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget)
{
// paint parent
AbstractContent::paint(painter, option, widget);
// scale painter for adapting the Text Rect to the Contents Rect
QRect cRect = contentsRect();
QRect sRect = m_textRect;
painter->save();
painter->translate(cRect.topLeft());
if (sRect.width() > 0 && sRect.height() > 0)
{
qreal xScale = (qreal)cRect.width() / (qreal)sRect.width();
qreal yScale = (qreal)cRect.height() / (qreal)sRect.height();
if (!qFuzzyCompare(xScale, 1.0) || !qFuzzyCompare(yScale, 1.0))
painter->scale(xScale, yScale);
}
QPen pen;
pen.setWidthF(3);
pen.setColor(QColor(0,0,0,255));
QBrush brush(QColor(255,255,255,255));
QFont font("Tahoma",88,QFont::Bold);
painter->setFont(font);
painter->setPen(pen);
painter->setBrush(brush);
painter->drawText(-m_textRect.topLeft(), m_text);
QPainterPath p;
p.addText(-m_textRect.topLeft(),font,m_text);
painter->drawPath(p);
painter->restore();
}
示例3: paint
void BlackEdgeTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
if (text.isEmpty())
return;
painter->setRenderHint(QPainter::Antialiasing);
if (outline > 0) {
QPen pen(Qt::black);
pen.setWidth(outline);
painter->setPen(pen);
}
QFontMetrics metric(font);
int height = metric.height() - metric.descent() + skip;
int i;
for (i = 0; i < text.length(); i++) {
QString text;
text.append(this->text.at(i));
QPainterPath path;
path.addText(0, (i + 1) * height, font, text);
if (outline > 0)
painter->drawPath(path);
painter->fillPath(path, color);
}
if (hasFocus()) {
QPen red_pen(Qt::red);
painter->setPen(red_pen);
QRectF rect = boundingRect();
painter->drawRect(-1, -1, rect.width() + 2, rect.height() + 2);
}
}
示例4: paint
void GraphicsTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
#if 0
//painter->drawRoundedRect(-10, -10, 20, 20, 5, 5);
//QStyleOptionGraphicsItem *o = const_cast<QStyleOptionGraphicsItem*>(option);
//o->state |= QStyle::State_HasFocus|QStyle::State_Selected;
//o->state |= QStyle::State_UpArrow;
//QGraphicsTextItem::paint(painter, o, widget);
QFontMetrics fm(font());
QRect boxRect = fm.boundingRect(boundingRect().toRect(), Qt::AlignHCenter ,toPlainText());
//QRectF boxRect = QRectF(0,0,40,15);
QPen testPen = QPen(Qt::red);
//painter->setPen(QPen(drawingColor,2));
//painter->drawRect(boxRect);
painter->setPen(testPen);
painter->drawText(boxRect,Qt::AlignCenter,toPlainText());
#endif
QPainterPath path;
//path.moveTo(20, 80);
//path.lineTo(20, 30);
//path.cubicTo(80, 0, 50, 50, 80, 80);
#if 0
// 只是改变字体border
QFontMetrics fm(font());
QString text=toPlainText();
QRect curRt = fm.boundingRect(boundingRect().toRect(), Qt::AlignHCenter ,text);
path.addText(curRt.left(),curRt.top()+fm.ascent(), font(), text);
QColor outlineColor(Qt::red);
QPen pen(outlineColor);
pen.setWidthF(1.5);
painter->setPen(pen);
painter->drawPath(path);
#endif
QGraphicsTextItem::paint(painter, option, widget);
}
示例5: paintContent
void ProgressFloatItem::paintContent( QPainter *painter )
{
// Stop repaint timer if it is already running
m_repaintTimer.stop();
if ( !active() ) {
return;
}
painter->save();
// Paint progress pie
int startAngle = 90 * 16; // 12 o' clock
int spanAngle = -ceil ( 360 * 16 * m_completed );
QRectF rect( contentRect() );
rect.adjust( 1, 1, -1, -1 );
painter->setBrush( QColor( Qt::white ) );
painter->setPen( Qt::NoPen );
painter->drawPie( rect, startAngle, spanAngle );
// Paint progress label
QFont myFont = font();
myFont.setPointSize( m_fontSize );
QString done = QString::number( (int) ( m_completed * 100 ) ) + '%';
int fontWidth = QFontMetrics( myFont ).boundingRect( done ).width();
QPointF baseline( padding() + 0.5 * ( rect.width() - fontWidth ), 0.75 * rect.height() );
QPainterPath path;
path.addText( baseline, myFont, done );
painter->setFont( myFont );
painter->setBrush( QBrush() );
painter->setPen( QPen() );
painter->drawPath( path );
painter->restore();
}
示例6: SetMusicFont
//-------------------------------------------------------------
void GDeviceQt::SetMusicFont( const VGFont * font )
{
if ( font == mCurrMusicFont )
return;
mCurrMusicFont = (GFontQt*)font;
#ifdef USE_CACHED_MUSIC_FONT
mCurrentFontRatio = mCurrMusicFont->GetSize()/float(CACHED_FONT_SIZE);
if ( mCurrentFontName != QString(font->GetName()) )
{
mCurrentFontName = QString( font->GetName() );
if ( mCachedMusicFont->contains( mCurrentFontName ) )
{
mCurrCachedMusicFont = &(*mCachedMusicFont)[mCurrentFontName];
return;
}
}
else
return;
GFontQt * cacheFont = (GFontQt*)(mSys->CreateVGFont( font->GetName() , CACHED_FONT_SIZE , font->GetProperties() ));
QFont qtFont(*(cacheFont->GetNativeFont()));
for ( int i = 0 ; i <= kMaxMusicalSymbolID ; i++ )
{
QString symbol = mCurrMusicFont->Symbol(i);
QPainterPath path;
path.addText( 0 , 0 , qtFont , symbol );
(*mCachedMusicFont)[mCurrentFontName][i] = path;
}
mCurrCachedMusicFont = &(*mCachedMusicFont)[mCurrentFontName];
#endif
}
示例7: drawTextCommon
static void drawTextCommon(GraphicsContext* ctx, const TextRun& run, const FloatPoint& point, int from, int to, const QFont& font, bool isComplexText)
{
if (to < 0)
to = run.length();
QPainter *p = ctx->platformContext();
QPen textFillPen;
if (ctx->textDrawingMode() & TextModeFill)
textFillPen = fillPenForContext(ctx);
QPen textStrokePen;
if (ctx->textDrawingMode() & TextModeStroke)
textStrokePen = strokePenForContext(ctx);
String sanitized = Font::normalizeSpaces(run.characters(), run.length());
QString string = fromRawDataWithoutRef(sanitized);
QPointF pt(point.x(), point.y());
if (from > 0 || to < run.length()) {
if (isComplexText) {
QTextLayout layout(string, font);
QTextLine line = setupLayout(&layout, run);
float x1 = line.cursorToX(from);
float x2 = line.cursorToX(to);
if (x2 < x1)
qSwap(x1, x2);
QFontMetrics fm(font);
int ascent = fm.ascent();
QRectF boundingRect(point.x() + x1, point.y() - ascent, x2 - x1, fm.height());
QRectF clip = boundingRect;
ContextShadow* ctxShadow = ctx->contextShadow();
if (ctxShadow->m_type != ContextShadow::NoShadow) {
qreal dx1 = 0, dx2 = 0, dy1 = 0, dy2 = 0;
if (ctxShadow->offset().x() > 0)
dx2 = ctxShadow->offset().x();
else
dx1 = -ctxShadow->offset().x();
if (ctxShadow->offset().y() > 0)
dy2 = ctxShadow->offset().y();
else
dy1 = -ctxShadow->offset().y();
// expand the clip rect to include the text shadow as well
clip.adjust(dx1, dx2, dy1, dy2);
clip.adjust(-ctxShadow->m_blurDistance, -ctxShadow->m_blurDistance, ctxShadow->m_blurDistance, ctxShadow->m_blurDistance);
}
p->save();
p->setClipRect(clip.toRect(), Qt::IntersectClip);
pt.setY(pt.y() - ascent);
if (ctxShadow->m_type != ContextShadow::NoShadow) {
ContextShadow* ctxShadow = ctx->contextShadow();
if (!ctxShadow->mustUseContextShadow(ctx)) {
p->save();
p->setPen(ctxShadow->m_color);
p->translate(ctxShadow->offset());
line.draw(p, pt);
p->restore();
} else {
QPainter* shadowPainter = ctxShadow->beginShadowLayer(ctx, boundingRect);
if (shadowPainter) {
// Since it will be blurred anyway, we don't care about render hints.
shadowPainter->setFont(p->font());
shadowPainter->setPen(ctxShadow->m_color);
line.draw(shadowPainter, pt);
ctxShadow->endShadowLayer(ctx);
}
}
}
p->setPen(textFillPen);
line.draw(p, pt);
p->restore();
return;
}
int skipWidth = QFontMetrics(font).width(string, from, Qt::TextBypassShaping);
pt.setX(pt.x() + skipWidth);
string = fromRawDataWithoutRef(sanitized, from, to - from);
}
p->setFont(font);
int flags = run.rtl() ? Qt::TextForceRightToLeft : Qt::TextForceLeftToRight;
if (!isComplexText && !(ctx->textDrawingMode() & TextModeStroke))
flags |= Qt::TextBypassShaping;
QPainterPath textStrokePath;
if (ctx->textDrawingMode() & TextModeStroke)
textStrokePath.addText(pt, font, string);
ContextShadow* ctxShadow = ctx->contextShadow();
if (ctxShadow->m_type != ContextShadow::NoShadow) {
if (ctx->textDrawingMode() & TextModeFill) {
if (ctxShadow->m_type != ContextShadow::BlurShadow) {
p->save();
p->setPen(ctxShadow->m_color);
p->translate(ctxShadow->offset());
p->drawText(pt, string, flags, run.expansion());
//.........这里部分代码省略.........
示例8: setupShapes
//! [3]
void Window::setupShapes()
{
QPainterPath truck;
//! [3]
truck.setFillRule(Qt::WindingFill);
truck.moveTo(0.0, 87.0);
truck.lineTo(0.0, 60.0);
truck.lineTo(10.0, 60.0);
truck.lineTo(35.0, 35.0);
truck.lineTo(100.0, 35.0);
truck.lineTo(100.0, 87.0);
truck.lineTo(0.0, 87.0);
truck.moveTo(17.0, 60.0);
truck.lineTo(55.0, 60.0);
truck.lineTo(55.0, 40.0);
truck.lineTo(37.0, 40.0);
truck.lineTo(17.0, 60.0);
truck.addEllipse(17.0, 75.0, 25.0, 25.0);
truck.addEllipse(63.0, 75.0, 25.0, 25.0);
//! [4]
QPainterPath clock;
//! [4]
clock.addEllipse(-50.0, -50.0, 100.0, 100.0);
clock.addEllipse(-48.0, -48.0, 96.0, 96.0);
clock.moveTo(0.0, 0.0);
clock.lineTo(-2.0, -2.0);
clock.lineTo(0.0, -42.0);
clock.lineTo(2.0, -2.0);
clock.lineTo(0.0, 0.0);
clock.moveTo(0.0, 0.0);
clock.lineTo(2.732, -0.732);
clock.lineTo(24.495, 14.142);
clock.lineTo(0.732, 2.732);
clock.lineTo(0.0, 0.0);
//! [5]
QPainterPath house;
//! [5]
house.moveTo(-45.0, -20.0);
house.lineTo(0.0, -45.0);
house.lineTo(45.0, -20.0);
house.lineTo(45.0, 45.0);
house.lineTo(-45.0, 45.0);
house.lineTo(-45.0, -20.0);
house.addRect(15.0, 5.0, 20.0, 35.0);
house.addRect(-35.0, -15.0, 25.0, 25.0);
//! [6]
QPainterPath text;
//! [6]
QFont font;
font.setPixelSize(50);
QRect fontBoundingRect = QFontMetrics(font).boundingRect(tr("Qt"));
text.addText(-QPointF(fontBoundingRect.center()), font, tr("Qt"));
//! [7]
shapes.append(clock);
shapes.append(house);
shapes.append(text);
shapes.append(truck);
connect(shapeComboBox, SIGNAL(activated(int)),
this, SLOT(shapeSelected(int)));
}
示例9: drawnewconnect
void MainWindow::drawnewconnect(int xxend, int yyend)
{
QGraphicsScene *scene = new QGraphicsScene(ui->graphicsView);
scene->setSceneRect(0,0,725,575);//розмір сцені
ui->graphicsView->setAlignment(Qt::AlignLeft|Qt::AlignTop );
connects u;
parsanddrow d;
QDebug qd= qDebug();
qApp->applicationDirPath() +"C:/Users/Igro/build-vns_kma-Desktop_Qt_5_1_1_MinGW_32bit-Debug/24.jpeg";
QPixmap pcc;
QPixmap modem;
QPixmap sw;
QPainterPath path;
QFont font;
font.setPixelSize(50);
//pcc.load("C:/Users/Igro/build-vns_kma-Desktop_Qt_5_1_1_MinGW_32bit-Debug/pc.png");
pcc.load("pc.png");
modem.load("modem.png");
sw.load("sw.png");
QString l; //назва приладу
int xbeg;
int ybeg;
int xend;
int yend;
xend=xxend;
yend=yyend;
int dd; //кілкість приладів
if(d.count(openfil())!=0)
{
dd=d.count(openfil());//кілкість рядків на 4 властивості отримаємо кілкість приладів
d.cord(openfil());//заповнення масивік кординатами та іменами (and mac)
for(int i=0;i<dd;i++)
{
if(d.getmac(i)==u.getbegin())
{
xbeg=d.getx(i);
ybeg=d.gety(i);
}
}
for(int h=0; h<dd; h++) //малювання
{
l=d.getdev(h);
if(l=="sw")
{
QGraphicsPixmapItem * a=scene->addPixmap(sw);
a->moveBy(d.getx(h),d.gety(h));
QFont font;
QPainterPath path;
a->setZValue(1);
font.setPixelSize(20);
font.setBold(false);
font.setFamily("Calibri");
path.addText(d.getx(h)-2,d.gety(h)+63,font,d.getname(h));
scene->addPath(path, QPen(QBrush(Qt::black), 1), QBrush(Qt::black));
}
if(l=="pc")
{
QGraphicsPixmapItem * b=scene->addPixmap(pcc);
b->moveBy(d.getx(h),d.gety(h));
b->setZValue(1);
QFont font;
QPainterPath path;
font.setPixelSize(20);
font.setBold(false);
font.setFamily("Calibri");
path.addText(d.getx(h)-2,d.gety(h)+63,font,d.getname(h));
scene->addPath(path, QPen(QBrush(Qt::black), 1), QBrush(Qt::black));
}
if(l=="modem")
{
QGraphicsPixmapItem * bc=scene->addPixmap(modem);
bc->moveBy(d.getx(h),d.gety(h));
bc->setZValue(1);
QFont font;
QPainterPath path;
font.setPixelSize(20);
font.setBold(false);
font.setFamily("Calibri");
path.addText(d.getx(h)-2,d.gety(h)+63,font,d.getname(h));
scene->addPath(path, QPen(QBrush(Qt::black), 1), QBrush(Qt::black));
}
if(l=="con")
{ int xpoch[dd];
int ypoch[dd];
int xend[dd];
int yend[dd];
for(int i=0; dd>i;i++)
{
if(d.gatmacconnect1(h)==d.getmac(i))
{
xpoch[h]=d.getx(i);
ypoch[h]=d.gety(i);
}
else
if(d.gatmacconnect2(h)==d.getmac(i))
{
xend[h]=d.getx(i);
yend[h]=d.gety(i);
//.........这里部分代码省略.........
示例10: drawinwindow
void MainWindow::drawinwindow()
{
parsanddrow d;
QGraphicsScene *scene = new QGraphicsScene(ui->graphicsView);
scene->setSceneRect(0,0,725,575);//розмір сцені
ui->graphicsView->setAlignment(Qt::AlignLeft|Qt::AlignTop );
if(d.count(openfil())!=0)
{
QPixmap pcc;
QPixmap modem;
QPixmap sw;
QPainterPath path;
QFont font;
font.setPixelSize(50);
//pcc.load("C:/Users/Igro/build-vns_kma-Desktop_Qt_5_1_1_MinGW_32bit-Debug/pc.png");
pcc.load("pc.png");
modem.load("modem.png");
sw.load("sw.png");
QString l; //назва приладу
QDebug qd= qDebug();
int dd; //кілкість приладів
dd=d.count(openfil());//кілкість рядків на 4 властивості отримаємо кілкість приладів
d.cord(openfil());//заповнення масивік кординатами та іменами (and mac)
if(dd)
for(int h=0; h<dd; h++) //малювання
{
l=d.getdev(h);
if(l=="sw")
{
QGraphicsPixmapItem * a=scene->addPixmap(sw);
a->moveBy(d.getx(h),d.gety(h));
QFont font;
QPainterPath path;
a->setZValue(1);
font.setPixelSize(20);
font.setBold(false);
font.setFamily("Calibri");
path.addText(d.getx(h)-2,d.gety(h)+63,font,d.getname(h));
scene->addPath(path, QPen(QBrush(Qt::black), 1), QBrush(Qt::black));
}
if(l=="pc")
{
QGraphicsPixmapItem * b=scene->addPixmap(pcc);
b->moveBy(d.getx(h),d.gety(h));
b->setZValue(1);
QFont font;
QPainterPath path;
font.setPixelSize(20);
font.setBold(false);
font.setFamily("Calibri");
path.addText(d.getx(h)-2,d.gety(h)+63,font,d.getname(h));
scene->addPath(path, QPen(QBrush(Qt::black), 1), QBrush(Qt::black));
}
if(l=="modem")
{
QGraphicsPixmapItem * bc=scene->addPixmap(modem);
bc->moveBy(d.getx(h),d.gety(h));
bc->setZValue(1);
QFont font;
QPainterPath path;
font.setPixelSize(20);
font.setBold(false);
font.setFamily("Calibri");
path.addText(d.getx(h)-2,d.gety(h)+63,font,d.getname(h));
scene->addPath(path, QPen(QBrush(Qt::black), 1), QBrush(Qt::black));
}
if(l=="con")
{ int xpoch[dd];
int ypoch[dd];
int xend[dd];
int yend[dd];
bool fir=false;
bool sec=false;
for(int i=0; dd>i;i++)
{
if(d.gatmacconnect1(h)==d.getmac(i))
{
xpoch[h]=d.getx(i);
ypoch[h]=d.gety(i);
fir=true;
}
else
if(d.gatmacconnect2(h)==d.getmac(i))
{
xend[h]=d.getx(i);
yend[h]=d.gety(i);
sec=true;
}
}
if(fir==false || sec==false)
{
d.delate(openfil(),h);
}
if(fir!=false && sec!=false)
scene->addLine(QLineF(xpoch[h]+15, ypoch[h]+15, xend[h]+15, yend[h]+15), QPen(Qt::blue, 2));
}
if((l!="modem")|(l!="sw")|(l!="pc"))
//.........这里部分代码省略.........
示例11: image
const Glyph& TextRenderer::getGlyph(char c) {
Glyph& glyph = _glyphs[c];
if (glyph.isValid()) {
return glyph;
}
// we use 'J' as a representative size for the solid block character
QChar ch = (c == SOLID_BLOCK_CHAR) ? QChar('J') : QChar(c);
QRect bounds = _metrics.boundingRect(ch);
if (bounds.isEmpty()) {
glyph = Glyph(0, QPoint(), QRect(), _metrics.width(ch));
return glyph;
}
// grow the bounds to account for effect, if any
if (_effectType == SHADOW_EFFECT) {
bounds.adjust(-_effectThickness, 0, 0, _effectThickness);
} else if (_effectType == OUTLINE_EFFECT) {
bounds.adjust(-_effectThickness, -_effectThickness, _effectThickness, _effectThickness);
}
// grow the bounds to account for antialiasing
bounds.adjust(-1, -1, 1, 1);
if (_x + bounds.width() > IMAGE_SIZE) {
// we can't fit it on the current row; move to next
_y += _rowHeight;
_x = _rowHeight = 0;
}
if (_y + bounds.height() > IMAGE_SIZE) {
// can't fit it on current texture; make a new one
glGenTextures(1, &_currentTextureID);
_x = _y = _rowHeight = 0;
glBindTexture(GL_TEXTURE_2D, _currentTextureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, IMAGE_SIZE, IMAGE_SIZE, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
_allTextureIDs.append(_currentTextureID);
} else {
glBindTexture(GL_TEXTURE_2D, _currentTextureID);
}
// render the glyph into an image and copy it into the texture
QImage image(bounds.width(), bounds.height(), QImage::Format_ARGB32);
if (c == SOLID_BLOCK_CHAR) {
image.fill(QColor(255, 255, 255));
} else {
image.fill(0);
QPainter painter(&image);
painter.setFont(_font);
if (_effectType == SHADOW_EFFECT) {
for (int i = 0; i < _effectThickness; i++) {
painter.drawText(-bounds.x() - 1 - i, -bounds.y() + 1 + i, ch);
}
} else if (_effectType == OUTLINE_EFFECT) {
QPainterPath path;
QFont font = _font;
font.setStyleStrategy(QFont::ForceOutline);
path.addText(-bounds.x() - 0.5, -bounds.y() + 0.5, font, ch);
QPen pen;
pen.setWidth(_effectThickness);
pen.setJoinStyle(Qt::RoundJoin);
pen.setCapStyle(Qt::RoundCap);
painter.setPen(pen);
painter.setRenderHint(QPainter::Antialiasing);
painter.drawPath(path);
}
painter.setPen(QColor(255, 255, 255));
painter.drawText(-bounds.x(), -bounds.y(), ch);
}
glTexSubImage2D(GL_TEXTURE_2D, 0, _x, _y, bounds.width(), bounds.height(), GL_RGBA, GL_UNSIGNED_BYTE, image.constBits());
glyph = Glyph(_currentTextureID, QPoint(_x, _y), bounds, _metrics.width(ch));
_x += bounds.width();
_rowHeight = qMax(_rowHeight, bounds.height());
glBindTexture(GL_TEXTURE_2D, 0);
return glyph;
}
示例12: initializeGlyph
void GLText::initializeGlyph(char ch)
{
Glyph glyph;
QPainterPath path;
if(debugTesselation) printf("Adding glyph %c\n",ch);
path.addText(0,0,font,QString((QChar)ch));
QList<QPolygonF> polygons = path.toSubpathPolygons();
if(debugTesselation){
printf("%d Sub-Polygons\n",polygons.size());
printf("Poly has %d vertices:\n",polygons.size());
}
int numVertices = 0;
double minX=DBL_MAX, minY=DBL_MAX, maxX=-DBL_MAX, maxY=-DBL_MAX;
for(int i=0; i<polygons.size(); i++){
if(debugTesselation) printf("Sub-Polygon %d:\n",i);
numVertices += polygons[i].size();
for(int k=0; k<polygons[i].size(); k++){
if(debugTesselation) printf("%8.3f,%8.3f\n",polygons[i][k].x(),polygons[i][k].y());
minX = min(minX, polygons[i][k].x());
maxX = max(maxX, polygons[i][k].x());
minY = min(minY, polygons[i][k].y());
maxY = max(maxY, polygons[i][k].y());
}
}
glyph.ascent = fabs(minY)/FontRenderSize;
glyph.descent = fabs(maxY)/FontRenderSize;
glyph.height = (maxY - minY)/FontRenderSize;
glyph.width = (maxX - minX)/FontRenderSize;
if(debugTesselation) printf("numVertices: %d\n",numVertices);
GLdouble vertices[numVertices][3];
int j=0;
for(int i=0; i<polygons.size(); i++){
for(int k=0; k<polygons[i].size(); k++){
vertices[j][0] = polygons[i][k].x()/FontRenderSize;
vertices[j][1] = -polygons[i][k].y()/FontRenderSize;
vertices[j][2] = 9;
j++;
}
}
GLUtesselator* tess = gluNewTess();
gluTessCallback(tess, GLU_TESS_BEGIN, (_GLUfuncptr) tessBeginCB);
gluTessCallback(tess, GLU_TESS_END, (_GLUfuncptr) tessEndCB);
gluTessCallback(tess, GLU_TESS_ERROR, (_GLUfuncptr) tessErrorCB);
gluTessCallback(tess, GLU_TESS_VERTEX, (_GLUfuncptr) tessVertexCB);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glyph.displayListID = glGenLists(1);
if(glyph.displayListID==GL_INVALID_VALUE){
printf("Unable to create display list!\n");
exit(1);
}
glNewList(glyph.displayListID, GL_COMPILE);
gluTessBeginPolygon(tess, 0);
j=0;
for(int i=0; i<polygons.size(); i++){
gluTessBeginContour(tess);
for(int k=0; k<polygons[i].size(); k++){
gluTessVertex(tess, vertices[j], vertices[j]);
j++;
}
gluTessEndContour(tess);
}
gluTessEndPolygon(tess);
gluDeleteTess(tess);
glEndList();
glPopMatrix();
glyph.compiled = true;
glyphs[ch] = glyph;
}
示例13: drawLabel
void PrimitivePainter::drawLabel(QPainterPath* R, QPainter* thePainter, qreal PixelPerM, QString str, QString strBg) const
{
if (!DrawLabel)
return;
if (str.isEmpty() && strBg.isEmpty())
return;
thePainter->save();
if (getLabelArea()) {
QPointF C(R->boundingRect().center());
drawPointLabel(C, str, strBg, thePainter, PixelPerM);
thePainter->restore();
return;
}
LineParameters lp = labelBoundary();
qreal WW = PixelPerM*lp.Proportional+lp.Fixed;
if (WW < 10) return;
//qreal WWR = qMax(PixelPerM*R->widthOf()*BackgroundScale+BackgroundOffset, PixelPerM*R->widthOf()*ForegroundScale+ForegroundOffset);
QPainterPath textPath;
QPainterPath tranformedRoadPath = *R;
QFont font = getLabelFont();
if (!str.isEmpty()) {
QRegion rg = thePainter->clipRegion();
font.setPixelSize(int(WW));
QFontMetrics metrics(font);
if (font.pixelSize() >= 5 && tranformedRoadPath.length() > metrics.width(str)) {
thePainter->setFont(font);
int repeat = int((tranformedRoadPath.length() / ((metrics.width(str) * LABEL_PATH_DISTANCE))) - 0.5);
int numSegment = repeat+1;
qreal lenSegment = tranformedRoadPath.length() / numSegment;
qreal startSegment = 0;
QPainterPath textPath;
do {
QRegion rg = thePainter->clipRegion();
qreal curLen = startSegment + ((lenSegment - metrics.width(str)) / 2);
int modIncrement = 1;
qreal modAngle = 0;
int modY = 0;
if (cos(angToRad(tranformedRoadPath.angleAtPercent((startSegment+(lenSegment/2))/tranformedRoadPath.length()))) < 0) {
modIncrement = -1;
modAngle = 180.0;
curLen += metrics.width(str);
}
for (int i = 0; i < str.length(); ++i) {
qreal t = tranformedRoadPath.percentAtLength(curLen);
QPointF pt = tranformedRoadPath.pointAtPercent(t);
qreal angle = tranformedRoadPath.angleAtPercent(t);
modY = (metrics.ascent()/2)-3;
QMatrix m;
m.translate(pt.x(), pt.y());
m.rotate(-angle+modAngle);
QPainterPath charPath;
charPath.addText(0, modY, font, str.mid(i, 1));
charPath = charPath * m;
textPath.addPath(charPath);
qreal incremenet = metrics.width(str[i]);
curLen += (incremenet * modIncrement);
}
startSegment += lenSegment;
} while (--repeat >= 0);
if (getLabelHalo()) {
thePainter->setPen(QPen(Qt::white, font.pixelSize()/6));
thePainter->drawPath(textPath);
}
thePainter->setPen(Qt::NoPen);
thePainter->setBrush(LabelColor);
thePainter->drawPath(textPath);
thePainter->setClipRegion(rg);
}
}
if (DrawLabelBackground && !strBg.isEmpty()) {
QRegion rg = thePainter->clipRegion();
font.setPixelSize(int(WW));
QFontMetrics metrics(font);
int repeat = int((tranformedRoadPath.length() / (metrics.width(strBg) * LABEL_STRAIGHT_DISTANCE)) - 0.5);
int numSegment = repeat+1;
qreal lenSegment = tranformedRoadPath.length() / numSegment;
qreal startSegment = 0;
do {
int modX = 0;
int modY = 0;
qreal curLen = startSegment + (lenSegment / 2);
qreal t = tranformedRoadPath.percentAtLength(curLen);
QPointF pt = tranformedRoadPath.pointAtPercent(t);
//.........这里部分代码省略.........
示例14: recreateTexture
void TextLayer::recreateTexture(VidgfxContext *gfx)
{
if(!m_isTexDirty)
return; // Don't waste any time if it hasn't changed
m_isTexDirty = false;
// Delete existing texture if one exists
if(m_texture != NULL)
vidgfx_context_destroy_tex(gfx, m_texture);
m_texture = NULL;
// Determine texture size. We need to keep in mind that the text in the
// document might extend outside of the layer's bounds.
m_document.setTextWidth(m_rect.width());
QSize size(
(int)ceilf(m_document.size().width()),
(int)ceilf(m_document.size().height()));
if(m_document.isEmpty() || size.isEmpty()) {
// Nothing to display
return;
}
// Create temporary canvas. We need to be careful here as text is rendered
// differently on premultiplied vs non-premultiplied pixel formats. On a
// premultiplied format text is rendered with subpixel rendering enabled
// while on a non-premultiplied format it is not. As we don't want subpixel
// rendering we use the standard ARGB32 format.
QSize imgSize(
size.width() + m_strokeSize * 2, size.height() + m_strokeSize * 2);
QImage img(imgSize, QImage::Format_ARGB32);
img.fill(Qt::transparent);
QPainter p(&img);
p.setRenderHint(QPainter::Antialiasing, true);
// Render text
//m_document.drawContents(&p);
// Render stroke
if(m_strokeSize > 0) {
#define STROKE_TECHNIQUE 0
#if STROKE_TECHNIQUE == 0
// Technique 0: Use QTextDocument's built-in text outliner
//quint64 timeStart = App->getUsecSinceExec();
QTextDocument *outlineDoc = m_document.clone(this);
QTextCharFormat format;
QPen pen(m_strokeColor, (double)(m_strokeSize * 2));
pen.setJoinStyle(Qt::RoundJoin);
format.setTextOutline(pen);
QTextCursor cursor(outlineDoc);
cursor.select(QTextCursor::Document);
cursor.mergeCharFormat(format);
// Take into account the stroke offset
p.translate(m_strokeSize, m_strokeSize);
//quint64 timePath = App->getUsecSinceExec();
outlineDoc->drawContents(&p);
delete outlineDoc;
//quint64 timeEnd = App->getUsecSinceExec();
//appLog() << "Path time = " << (timePath - timeStart) << " usec";
//appLog() << "Render time = " << (timeEnd - timePath) << " usec";
//appLog() << "Full time = " << (timeEnd - timeStart) << " usec";
#elif STROKE_TECHNIQUE == 1
// Technique 1: Create a text QPainterPath and stroke it
quint64 timeStart = App->getUsecSinceExec();
// Create the path for the text's stroke
QPainterPath path;
QTextBlock &block = m_document.firstBlock();
int numBlocks = m_document.blockCount();
for(int i = 0; i < numBlocks; i++) {
QTextLayout *layout = block.layout();
for(int j = 0; j < layout->lineCount(); j++) {
QTextLine &line = layout->lineAt(j);
const QString text = block.text().mid(
line.textStart(), line.textLength());
QPointF pos = layout->position() + line.position();
pos.ry() += line.ascent();
//appLog() << pos << ": " << text;
path.addText(pos, block.charFormat().font(), text);
}
block = block.next();
}
quint64 timePath = App->getUsecSinceExec();
path = path.simplified(); // Fixes gaps with large stroke sizes
quint64 timeSimplify = App->getUsecSinceExec();
// Render the path
//p.strokePath(path, QPen(m_strokeColor, m_strokeSize));
// Convert it to a stroke
QPainterPathStroker stroker;
stroker.setWidth(m_strokeSize);
//stroker.setCurveThreshold(2.0);
stroker.setJoinStyle(Qt::RoundJoin);
//.........这里部分代码省略.........
示例15: if
void
RemapImage::drawRawValue(QPainter *p)
{
QVariant vr = m_rawValue;
QVariant vp = m_pvlValue;
QString str;
bool isString = false;
if (vr.type() == QVariant::String)
{
isString = true;
str = vr.toString();
if (str == "OutOfBounds")
return;
}
int xp = m_cursorPos.x();
int yp = m_cursorPos.y();
str = QString("%1 %2 %3").\
arg(m_pickHeight).\
arg(m_pickWidth).\
arg(m_pickDepth);
if (isString)
str += vr.toString();
else
{
if (vr.type() == QVariant::UInt)
str += QString(" ui(%1)").arg(vr.toUInt());
else if (vr.type() == QVariant::Int)
str += QString(" u(%1)").arg(vr.toInt());
else if (vr.type() == QVariant::Double)
str += QString(" f(%1)").arg(vr.toDouble());
str += QString("->(%1)").arg(vp.toUInt());
}
QFont pfont = QFont("Helvetica", 10);
QPainterPath pp;
pp.addText(QPointF(0,0),
pfont,
str);
QRectF br = pp.boundingRect();
float by = br.height()/2;
float bw = br.width();
int x = xp-bw-30;
int xe = xp-20;
if (x < 1)
{
x = xp+20;
xe = x;
}
p->setPen(Qt::darkRed);
p->setBrush(QColor(0,0,0,200));
p->drawRect(x, yp-by,
bw+10, 2*by+5);
p->setPen(Qt::white);
p->drawText(x+5, yp+by,
str);
p->setPen(Qt::black);
p->drawLine(xe, yp, xp, yp);
}