Ishark
6th July 2007, 19:29
Hello,
I'm trying to generate a modified image starting from a preexisting PNG file and drawing some text on it. I'm not getting what I think I should get :)
In particular, I have some issues with font sizes.
I have found that the PNG resolution plays a role in the calculation of the actual pixel size of the font, if I increase the resolution and keep the font size fixed, the actual rendered text is smaller. The sizes do not match what I see if I do the same in inkscape, but this is not a problem. My problem is that there seems to be a "minimum pixel size" which limits the size of the smallest font I can draw. Right now I have the PNG at 72x72 dpi and a font size of 2 looks identical to font size 10.
The code:
int main(int argc, char **argv)
{
QApplication a(argc, argv);
QImage* card = new QImage("blank72.png");
QPainter* painter = new QPainter(card);
QFont* FontText = new QFont("Serif", 2, QFont::Normal);
QFont* FontText2 = new QFont("Serif", 10, QFont::Normal);
painter->setRenderHint(QPainter::TextAntialiasing, true);
painter->setPen(Qt::black);
painter->setFont(*FontText);
painter->drawText(QRect(0,0,256,128), Qt::TextWordWrap, "Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt");
painter->setFont(*FontText2);
painter->drawText(QRect(0,128,256,128), Qt::TextWordWrap, "Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt");
QLabel* label = new QLabel(0);
label->setPixmap(QPixmap::fromImage(*card));
label->show();
return a.exec();
}
blank72.png is a 256x256 white image with 72dpi resolution.
Side question: is there any easy way to have the text justified?
I'm trying to generate a modified image starting from a preexisting PNG file and drawing some text on it. I'm not getting what I think I should get :)
In particular, I have some issues with font sizes.
I have found that the PNG resolution plays a role in the calculation of the actual pixel size of the font, if I increase the resolution and keep the font size fixed, the actual rendered text is smaller. The sizes do not match what I see if I do the same in inkscape, but this is not a problem. My problem is that there seems to be a "minimum pixel size" which limits the size of the smallest font I can draw. Right now I have the PNG at 72x72 dpi and a font size of 2 looks identical to font size 10.
The code:
int main(int argc, char **argv)
{
QApplication a(argc, argv);
QImage* card = new QImage("blank72.png");
QPainter* painter = new QPainter(card);
QFont* FontText = new QFont("Serif", 2, QFont::Normal);
QFont* FontText2 = new QFont("Serif", 10, QFont::Normal);
painter->setRenderHint(QPainter::TextAntialiasing, true);
painter->setPen(Qt::black);
painter->setFont(*FontText);
painter->drawText(QRect(0,0,256,128), Qt::TextWordWrap, "Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt");
painter->setFont(*FontText2);
painter->drawText(QRect(0,128,256,128), Qt::TextWordWrap, "Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt Qt");
QLabel* label = new QLabel(0);
label->setPixmap(QPixmap::fromImage(*card));
label->show();
return a.exec();
}
blank72.png is a 256x256 white image with 72dpi resolution.
Side question: is there any easy way to have the text justified?