Skip to content

Commit

Permalink
+ font testing
Browse files Browse the repository at this point in the history
  • Loading branch information
andryblack committed May 31, 2010
1 parent e67ee01 commit 612b29a
Show file tree
Hide file tree
Showing 10 changed files with 579 additions and 27 deletions.
11 changes: 8 additions & 3 deletions FontBuilder.pro
Expand Up @@ -56,7 +56,9 @@ SOURCES += main.cpp \
imagewriterfactory.cpp \
image/builtinimagewriter.cpp \
exporters/zfiexporter.cpp \
image/targawriter.cpp
image/targawriter.cpp \
fonttestframe.cpp \
fonttestwidget.cpp
HEADERS += fontbuilder.h \
colorbutton.h \
fontselectframe.h \
Expand All @@ -82,13 +84,16 @@ HEADERS += fontbuilder.h \
imagewriterfactory.h \
image/builtinimagewriter.h \
exporters/zfiexporter.h \
image/targawriter.h
image/targawriter.h \
fonttestframe.h \
fonttestwidget.h
FORMS += fontbuilder.ui \
fontselectframe.ui \
fontoptionsframe.ui \
charactersframe.ui \
layoutconfigframe.ui \
outputframe.ui
outputframe.ui \
fonttestframe.ui
TRANSLATIONS = fontbuilder_en.ts \
fontbuilder_ru.ts
QT += xml
Expand Down
55 changes: 38 additions & 17 deletions fontbuilder.cpp
Expand Up @@ -109,8 +109,14 @@ FontBuilder::FontBuilder(QWidget *parent) :

ui->frameOutput->setConfig(m_output_config);
ui->frameFontSelect->setConfig(m_font_config);

ui->fontTestFrame->setLayoutData(m_layout_data);
ui->fontTestFrame->setRendererData(&m_font_renderer->data());

m_font_config->blockSignals(font_config_block);
m_font_config->emmitChange();

ui->fontTestFrame->refresh();
}

FontBuilder::~FontBuilder()
Expand Down Expand Up @@ -195,35 +201,50 @@ void FontBuilder::on_comboBoxLayouter_currentIndexChanged(QString name)
}

void FontBuilder::onRenderedChanged() {

ui->fontTestFrame->refresh();
}

void FontBuilder::onLayoutChanged() {
QImage image (m_layout_data->width(),m_layout_data->height(),QImage::Format_ARGB32);
image.fill(0);
{
QPainter painter(&image);
foreach (const LayoutChar& c,m_layout_data->placed()) {
m_font_renderer->placeImage(painter,c.symbol,
c.x + m_layout_config->offsetLeft(),
c.y + m_layout_config->offsetTop()
);
}
}
m_layout_data->setImage(image);
QPixmap pixmap(m_layout_data->width(),m_layout_data->height());
pixmap.fill(QColor(0,0,0,255));
QPainter painter(&pixmap);
foreach (const LayoutChar& c,m_layout_data->placed())
m_font_renderer->placeImage(painter,c.symbol,
c.x + m_layout_config->offsetLeft(),
c.y + m_layout_config->offsetTop()
);
if (ui->checkBoxDrawGrid->isChecked()) {
painter.setPen(QColor(255,0,255,255));
if (m_layout_config->onePixelOffset())
foreach (const LayoutChar& c,m_layout_data->placed()) {
painter.drawRect(c.x-1,c.y-1,c.w,c.h);
}
else
foreach (const LayoutChar& c,m_layout_data->placed()) {
painter.drawRect(c.x,c.y,c.w-1,c.h-1);
}

{
QPainter painter(&pixmap);
painter.drawImage(0,0,image);

if (ui->checkBoxDrawGrid->isChecked()) {
painter.setPen(QColor(255,0,255,255));
if (m_layout_config->onePixelOffset())
foreach (const LayoutChar& c,m_layout_data->placed()) {
painter.drawRect(c.x-1,c.y-1,c.w,c.h);
}
else
foreach (const LayoutChar& c,m_layout_data->placed()) {
painter.drawRect(c.x,c.y,c.w-1,c.h-1);
}
}
}


ui->label_Image->setPixmap(pixmap);
ui->label_Image->repaint();
ui->label_ImageSize->setText(tr("Image size: ")+
QString().number(m_layout_data->width()) + "x" +
QString().number(m_layout_data->height())
);
ui->fontTestFrame->refresh();
}

void FontBuilder::onFontNameChanged() {
Expand Down
26 changes: 22 additions & 4 deletions fontbuilder.ui
Expand Up @@ -186,7 +186,7 @@
<item>
<widget class="QTabWidget" name="tabWidget_2">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab_Preview">
<attribute name="title">
Expand All @@ -203,8 +203,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>223</width>
<height>408</height>
<width>264</width>
<height>393</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
Expand Down Expand Up @@ -300,6 +300,18 @@
<attribute name="title">
<string>Test font</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="FontTestFrame" name="fontTestFrame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
Expand All @@ -311,7 +323,7 @@
<x>0</x>
<y>0</y>
<width>612</width>
<height>22</height>
<height>31</height>
</rect>
</property>
</widget>
Expand Down Expand Up @@ -349,6 +361,12 @@
<header>outputframe.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>FontTestFrame</class>
<extends>QFrame</extends>
<header>fonttestframe.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
Expand Down
75 changes: 75 additions & 0 deletions fonttestframe.cpp
@@ -0,0 +1,75 @@
/**
* Copyright (c) 2010-2010 Andrey AndryBlack Kunitsyn
* email:support.andryblack@gmail.com
*
* Report bugs and download new versions at http://code.google.com/p/fontbuilder
*
* This software is distributed under the MIT License.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

#include "fonttestframe.h"
#include "ui_fonttestframe.h"

FontTestFrame::FontTestFrame(QWidget *parent) :
QFrame(parent),
ui(new Ui::FontTestFrame)
{
ui->setupUi(this);
ui->drawWidget->setText(ui->plainTextEdit->document()->toPlainText());
}

FontTestFrame::~FontTestFrame()
{
delete ui;
}

void FontTestFrame::changeEvent(QEvent *e)
{
QFrame::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}


void FontTestFrame::setLayoutData(const LayoutData* data) {
ui->drawWidget->setLayoutData(data);
}

void FontTestFrame::setRendererData(const RendererData* data) {
ui->drawWidget->setRendererData(data);
}

void FontTestFrame::on_plainTextEdit_textChanged()
{
ui->drawWidget->setText(ui->plainTextEdit->document()->toPlainText());
}

void FontTestFrame::refresh() {
ui->drawWidget->refresh();
}
64 changes: 64 additions & 0 deletions fonttestframe.h
@@ -0,0 +1,64 @@
/**
* Copyright (c) 2010-2010 Andrey AndryBlack Kunitsyn
* email:support.andryblack@gmail.com
*
* Report bugs and download new versions at http://code.google.com/p/fontbuilder
*
* This software is distributed under the MIT License.
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

#ifndef FONTTESTFRAME_H
#define FONTTESTFRAME_H

#include <QFrame>

namespace Ui {
class FontTestFrame;
}

class LayoutData;
struct RendererData;

class FontTestFrame : public QFrame {
Q_OBJECT
public:
FontTestFrame(QWidget *parent = 0);
~FontTestFrame();

void setLayoutData(const LayoutData* data);
void setRendererData(const RendererData* data);

public slots:
void refresh();
protected:
void changeEvent(QEvent *e);

private:
Ui::FontTestFrame *ui;

private slots:
void on_plainTextEdit_textChanged();
};

#endif // FONTTESTFRAME_H

0 comments on commit 612b29a

Please sign in to comment.