Basic font rendering now working nicely.
1.1 --- a/MiniDisplay/BitArray.cpp Tue May 27 22:14:29 2014 +0200
1.2 +++ b/MiniDisplay/BitArray.cpp Wed May 28 08:06:27 2014 +0200
1.3 @@ -124,7 +124,9 @@
1.4 * Returned : None
1.5 ***************************************************************************/
1.6 BitArray::BitArray(const int numBits):
1.7 - m_NumBits(numBits)
1.8 + m_NumBits(numBits),
1.9 + m_Array(NULL),
1.10 + m_OwnsBuffer(true)
1.11 {
1.12 m_SizeInBytes = BITS_TO_CHARS(numBits);
1.13
1.14 @@ -146,10 +148,12 @@
1.15 * Effects : Allocates vectory for array bits
1.16 * Returned : None
1.17 ***************************************************************************/
1.18 -BitArray::BitArray(unsigned char *array, const int numBits):
1.19 +BitArray::BitArray(unsigned char *array, const int numBits,bool aOwnsBuffer):
1.20 m_NumBits(numBits),
1.21 - m_Array(array)
1.22 + m_Array(array),
1.23 + m_OwnsBuffer(aOwnsBuffer)
1.24 {
1.25 +
1.26 }
1.27
1.28 /***************************************************************************
1.29 @@ -162,7 +166,11 @@
1.30 ***************************************************************************/
1.31 BitArray::~BitArray(void)
1.32 {
1.33 - delete[] m_Array;
1.34 + if (m_OwnsBuffer)
1.35 + {
1.36 + delete[] m_Array;
1.37 + m_Array = NULL;
1.38 + }
1.39 }
1.40
1.41 /***************************************************************************
2.1 --- a/MiniDisplay/BitArray.h Tue May 27 22:14:29 2014 +0200
2.2 +++ b/MiniDisplay/BitArray.h Wed May 28 08:06:27 2014 +0200
2.3 @@ -95,14 +95,14 @@
2.4 {
2.5 public:
2.6 BitArray(const int numBits);
2.7 - BitArray(unsigned char *array, const int numBits);
2.8 + BitArray(unsigned char *array, const int numBits, bool aOwnsBuffer);
2.9
2.10 virtual ~BitArray(void);
2.11
2.12 void Dump(std::ostream &outStream);
2.13
2.14 - const unsigned int SizeInBits() { return m_NumBits; };
2.15 - const unsigned int SizeInBytes() { return m_SizeInBytes; };
2.16 + const unsigned int SizeInBits() { return m_NumBits; }
2.17 + const unsigned int SizeInBytes() { return m_SizeInBytes; }
2.18
2.19 /* set/clear functions */
2.20 void SetAll(void);
2.21 @@ -155,6 +155,7 @@
2.22 unsigned int m_NumBits; /* number of bits in the array */
2.23 unsigned int m_SizeInBytes;
2.24 unsigned char *m_Array; /* vector of characters */
2.25 + bool m_OwnsBuffer;
2.26 };
2.27
2.28 #endif /* ndef BIT_ARRAY_H */
3.1 --- a/MiniDisplay/FutabaVfd.cpp Tue May 27 22:14:29 2014 +0200
3.2 +++ b/MiniDisplay/FutabaVfd.cpp Wed May 28 08:06:27 2014 +0200
3.3 @@ -131,7 +131,7 @@
3.4
3.5 /**
3.6 */
3.7 -void GP1212A01A::BitBlit(BitArray& aBitmap, int aSrcWidth, int aSrcHeight, int aTargetX, int aTargetY) const
3.8 +void GP1212A01A::BitBlit(const BitArray& aBitmap, int aSrcWidth, int aSrcHeight, int aTargetX, int aTargetY) const
3.9 {
3.10 //TODO: amend loop values so that we don't keep on looping past our frame buffer dimensions.
3.11 for (int i=0;i<aSrcWidth;i++)
3.12 @@ -443,4 +443,4 @@
3.13 Clear();
3.14 SwapBuffers();
3.15 Clear();
3.16 - }
3.17 \ No newline at end of file
3.18 + }
4.1 --- a/MiniDisplay/FutabaVfd.h Tue May 27 22:14:29 2014 +0200
4.2 +++ b/MiniDisplay/FutabaVfd.h Wed May 28 08:06:27 2014 +0200
4.3 @@ -127,7 +127,7 @@
4.4 virtual void SetPixel(unsigned char aX, unsigned char aY, bool aOn);
4.5 virtual void SetAllPixels(unsigned char aPattern);
4.6 virtual int FrameBufferSizeInBytes() const {return KGP12xFrameBufferSizeInBytes;}
4.7 - virtual void BitBlit(BitArray& aBitmap, int aSrcWidth, int aSrcHeight, int aTargetX, int aTargetY) const;
4.8 + virtual void BitBlit(const BitArray& aBitmap, int aSrcWidth, int aSrcHeight, int aTargetX, int aTargetY) const;
4.9 //From FutabaVfd
4.10 virtual void SetBrightness(int aBrightness);
4.11 virtual void Clear();
5.1 --- a/MiniDisplay/minidisplay.cpp Tue May 27 22:14:29 2014 +0200
5.2 +++ b/MiniDisplay/minidisplay.cpp Wed May 28 08:06:27 2014 +0200
5.3 @@ -73,11 +73,15 @@
5.4 void MiniDisplay::setFont(const QFont& aFont)
5.5 {
5.6 iFont=aFont;
5.7 + iFont.setStyleStrategy(QFont::NoAntialias);
5.8 QString strDemo="0123456789ABCDEF";
5.9 QFontMetrics metrics(iFont);
5.10 - QSize size(metrics.width(strDemo),metrics.height());
5.11 + int w=metrics.width(strDemo);
5.12 + int h=metrics.height();
5.13 + QSize size(w,h);
5.14 QImage image(size,QImage::Format_Mono);
5.15 image.fill(0xFFFFFFFF);
5.16 + //Draw some text into our image
5.17 {
5.18 QPainter painter(&image);
5.19 //painter.begin(&image);
5.20 @@ -85,6 +89,27 @@
5.21 painter.setFont(iFont);
5.22 painter.drawText(0,metrics.ascent(),strDemo);
5.23 }
5.24 - //painter.end();
5.25 + //Save image as PNG for validation
5.26 image.save("font.png");
5.27 + //
5.28 + //int sizeInBytes=image.byteCount();
5.29 + int pixelCount=w*h;
5.30 + BitArray bits(pixelCount);
5.31 +
5.32 + for (int i=0;i<w;i++)
5.33 + {
5.34 + for (int j=0;j<h;j++)
5.35 + {
5.36 + QRgb color=image.pixel(i,j);
5.37 + if (color!=0xffffffff)
5.38 + {
5.39 + bits.SetBit(i*h+j);
5.40 + }
5.41 + }
5.42 + }
5.43 +
5.44 + iDisplay.Clear();
5.45 + iDisplay.BitBlit(bits,w,h,0,0);
5.46 + iDisplay.SwapBuffers();
5.47 + //
5.48 }