Skip to content

Commit

Permalink
Adds PNG export
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasfalk committed Sep 15, 2024
1 parent 11e84ab commit 9d02ba0
Show file tree
Hide file tree
Showing 13 changed files with 226 additions and 0 deletions.
Binary file added Doc/Img/Frame_ISO5457.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Doc/Img/Frame_Plain.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Doc/Img/TitleBlock_FreeCAD_Style_A.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Doc/Img/TitleBlock_ISO7200_Style_A.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Doc/Img/TitleBlock_ISO7200_Style_B.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ For the font [osifont](https://github.com/hikikomori82/osifont) was used. ISO fo

## Styles

### Frames

* Plain
![Plain Frame](/Doc/Img/Frame_Plain.png)

## Limitations

### KiCAD 8
Expand Down
14 changes: 14 additions & 0 deletions Src/Threads/universaldrawthread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "UniversalDraw/FreeCADSvg/freecadsvg.h"
#include "UniversalDraw/KiCAD8/kicad8.h"
#include "UniversalDraw/Html/htmldraw.h"
#include "UniversalDraw/PngQtPaint/pngqtpaint.h"

UniversalDrawThread::UniversalDrawThread() { }

Expand Down Expand Up @@ -48,6 +49,10 @@ void UniversalDrawThread::run()
qInfo() << "Html";
runHtml();
break;
case DrawingFormate::PngQtPaint:
qInfo() << "Png";
runPng();
break;
default:
break;
}
Expand Down Expand Up @@ -139,3 +144,12 @@ void UniversalDrawThread::runHtml()

m_pageStyle.draw(draw);
}

void UniversalDrawThread::runPng()
{
std::shared_ptr<PngQtPaint> draw = std::make_shared<PngQtPaint>();

draw->setFileName(m_fileName + ".qt.png");

m_pageStyle.draw(draw);
}
4 changes: 4 additions & 0 deletions Src/Threads/universaldrawthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ enum class DrawingFormate {
SvgQtPaint,
///
Html,
///
PngQtPaint,
};

///
Expand Down Expand Up @@ -130,6 +132,8 @@ class UniversalDrawThread : public QThread
void runSvgQtPaint();

void runHtml();

void runPng();
};

#endif // UNIVERSALDRAWTHREAD_H
2 changes: 2 additions & 0 deletions Src/UniversalDraw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ add_library(UniversalDraw STATIC
KiCAD8/kicad8.cpp
Html/htmldraw.h
Html/htmldraw.cpp
PngQtPaint/pngqtpaint.h
PngQtPaint/pngqtpaint.cpp
)

target_link_libraries(UniversalDraw PRIVATE
Expand Down
93 changes: 93 additions & 0 deletions Src/UniversalDraw/PngQtPaint/pngqtpaint.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include "pngqtpaint.h"
#include "qcolor.h"
#include "qnamespace.h"
#include "qpixmap.h"

#include <QFile>

PngQtPaint::PngQtPaint() : QtPainterDrawer() { }

// void PngQtPaint::drawText(QPointF position, QString text, double textSize,
// TextHeightAnchor textHeightAnchor, TextWidthAnchor textWidthAnchor,
// double lineWidth, QString font, QString name, bool isEditable)
// {
// if (isEditable && !this->showEditable()) {
// return;
// }

// QFont qFont(font);
// QFont qFontA(font);
// qFont.setPointSizeF(((textSize * std::sqrt(2)) / m_resolutionPMM)
// * 2.8346456692913); // 18897.6378
// qFontA.setPointSizeF(100);
// double posX = position.x();
// double posY = position.y();
// QFontMetrics fm(qFontA);

// if (textWidthAnchor == TextWidthAnchor::Left) {
// } else if (textWidthAnchor == TextWidthAnchor::Center) {
// posX -= (textSize * (fm.size(Qt::TextDontPrint, text).width() / double(100))) / 2;
// } else if (textWidthAnchor == TextWidthAnchor::Right) {
// posX -= (textSize * (fm.size(Qt::TextDontPrint, text).width() / double(100)));
// }

// if (textHeightAnchor == TextHeightAnchor::Top) {
// posY += textSize;
// } else if (textHeightAnchor == TextHeightAnchor::Middle) {
// posY += (textSize / 2);
// } else if (textHeightAnchor == TextHeightAnchor::Bottom) {
// }

// QPen pen(Qt::black);
// if (editableBlue() && isEditable) {
// pen = QPen(Qt::blue);
// }

// pen.setStyle(Qt::SolidLine);
// pen.setWidthF(lineWidth);
// painter()->setPen(pen);
// painter()->setBrush(Qt::NoBrush);

// painter()->setFont(qFont);
// painter()->drawText(QPointF(posX, posY), text);
// }

bool PngQtPaint::start()
{
m_image = std::shared_ptr<QImage>(new QImage((int)(this->width() * m_resolutionPMM),
(int)(this->height() * m_resolutionPMM),
QImage::Format_ARGB32));
this->setPainter(std::shared_ptr<QPainter>(new QPainter(m_image.get())));
this->painter()->setTransform(QTransform().scale(m_resolutionPMM, m_resolutionPMM));
return true;
}

bool PngQtPaint::end()
{
// this->painter()->drawPixmap(10, 130, 50, 50, pixmap);
this->painter()->end();
m_image->save(this->fileName());
return true;
}

int PngQtPaint::resolutionDPI() const
{
return m_resolutionDPI;
}

void PngQtPaint::setResolutionDPI(int newResolutionDPI)
{
m_resolutionDPI = newResolutionDPI;
m_resolutionPMM = m_resolutionDPI * (1 / 25.4);
}

double PngQtPaint::resolutionPMM() const
{
return m_resolutionPMM;
}

void PngQtPaint::setResolutionPMM(double newResolutionPMM)
{
m_resolutionPMM = newResolutionPMM;
m_resolutionDPI = int(m_resolutionPMM * 25.4);
}
90 changes: 90 additions & 0 deletions Src/UniversalDraw/PngQtPaint/pngqtpaint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#ifndef PNGQTPAINT_H
#define PNGQTPAINT_H

#include <QPainter>
#include <QSvgRenderer>
#include <QPdfWriter>

#include "UniversalDraw/universaldraw.h"
#include "UniversalDraw/QtPaint/qtpainterdrawer.h"

///
/// \brief The PngQtPaint class is used to draw a PDF with the Qt Painter
///
class PngQtPaint : public QtPainterDrawer
{
public:
///
/// \brief PngQtPaint is a class that uses the QPainter class to draw
///
explicit PngQtPaint();

///
/// \brief drawText draws Text on the given position
/// \param position is the Position of the Text(Text Anchor) in mm
/// \param text is the text that needs to be drawn
/// \param textSize is the height/size of the text in mm
/// \param textHeightAnchor is the position of the text anchor in the height
/// \param textWidthAnchor is the position of the text anchor in the width
/// \param lineWidth is the width of the text line in mm
/// \param font is the name of the font
/// \param isEditable defines if the text field is editable(true) or not(false), this does
/// nothing with base
/// \param name is the name that the text field is given, often used for
/// variable/editable text
///
// virtual void drawText(QPointF position, QString text, double textSize,
// TextHeightAnchor textHeightAnchor, TextWidthAnchor textWidthAnchor,
// double lineWidth, QString font = QString::fromLatin1("osifont"),
// QString name = QString::fromLatin1(""), bool isEditable = false)
// override;

///
/// \brief start initialises the file and make everything ready to be drawn in to
/// \return true if successful
///
virtual bool start() override;

///
/// \brief end finishes and closes the file
/// \return true if successful
///
virtual bool end() override;

///
/// \brief resolutionDPI is the general resolution the PDF is generated with in DPI
/// \return
///
int resolutionDPI() const;
///
/// \brief setResolutionDPI sets the general resolution the PDF is generated with in DPI
/// \param newResolutionDPI
///
void setResolutionDPI(int newResolutionDPI);

///
/// \brief resolutionPMM is the general resolution the PDF is generated with in Px Per mm
/// \return
///
double resolutionPMM() const;
///
/// \brief setResolutionPMM sets the general resolution the PDF is generated with in Px Per mm
/// \param newResolutionPMM
///
void setResolutionPMM(double newResolutionPMM);

private:
///
std::shared_ptr<QImage> m_image;

///
/// \brief m_resolutionDPI the used resolution of the drawing coordinates
///
int m_resolutionDPI = 1200;
///
/// \brief m_resolutionPMM the used resolution of the drawing coordinates in Px per mm
///
double m_resolutionPMM = m_resolutionDPI * (1 / 25.4);
};

#endif // PNGQTPAINT_H
4 changes: 4 additions & 0 deletions Src/Window/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,10 @@ QList<DrawingFormate> UTGMainWindow::getDrawingFormates()
ret.append(DrawingFormate::Html);
}

if (m_ui->QtPngCheckBox->isChecked()) {
ret.append(DrawingFormate::PngQtPaint);
}

return ret;
}

Expand Down
14 changes: 14 additions & 0 deletions Src/Window/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,20 @@
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QCheckBox" name="QtPngCheckBox">
<property name="text">
<string>Qt PNG</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
Expand Down

0 comments on commit 9d02ba0

Please sign in to comment.