Basic font rendering now working nicely.
1 #include "minidisplay.h"
4 MiniDisplay::MiniDisplay(QQuickItem *parent):
7 // By default, QQuickItem does not draw anything. If you subclass
8 // QQuickItem to create a visual item, you will need to uncomment the
9 // following line and re-implement updatePaintNode()
11 // setFlag(ItemHasContents, true);
13 //qDebug() << "New MiniDisplay";
16 MiniDisplay::~MiniDisplay()
18 //qDebug() << "Delete MiniDisplay";
22 void MiniDisplay::open()
36 void MiniDisplay::close()
43 bool MiniDisplay::isOpen()
45 return iDisplay.IsOpen();
48 void MiniDisplay::clear()
50 if (!iDisplay.IsOpen()) return;
55 void MiniDisplay::fill()
57 if (!iDisplay.IsOpen()) return;
59 iDisplay.SetAllPixels(0xFF);
62 void MiniDisplay::swapBuffers()
64 if (!iDisplay.IsOpen()) return;
66 iDisplay.SwapBuffers();
73 void MiniDisplay::setFont(const QFont& aFont)
76 iFont.setStyleStrategy(QFont::NoAntialias);
77 QString strDemo="0123456789ABCDEF";
78 QFontMetrics metrics(iFont);
79 int w=metrics.width(strDemo);
80 int h=metrics.height();
82 QImage image(size,QImage::Format_Mono);
83 image.fill(0xFFFFFFFF);
84 //Draw some text into our image
86 QPainter painter(&image);
87 //painter.begin(&image);
88 painter.setPen(0xFF000000);
89 painter.setFont(iFont);
90 painter.drawText(0,metrics.ascent(),strDemo);
92 //Save image as PNG for validation
93 image.save("font.png");
95 //int sizeInBytes=image.byteCount();
97 BitArray bits(pixelCount);
101 for (int j=0;j<h;j++)
103 QRgb color=image.pixel(i,j);
104 if (color!=0xffffffff)
112 iDisplay.BitBlit(bits,w,h,0,0);
113 iDisplay.SwapBuffers();