File: PrinterInterface.cpp

package info (click to toggle)
herculesstudio 1.5.0-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,376 kB
  • sloc: cpp: 17,077; xml: 21; makefile: 13
file content (122 lines) | stat: -rw-r--r-- 4,158 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "PrinterInterface.h"
#include "Environment.h"
#include "HerculesStudio.h"

#include <QHostAddress>
#include <QTcpSocket>
#include <QPainter> //TODO move to PagePrinter

BasicPrinter::BasicPrinter()
{
}


GenericPagePrinter::GenericPagePrinter(StationeryPtr &stationery, float scaling) :
    mStationery(stationery),  mPen(NULL), mLogo(QPixmap(2200,1200)), mLogoWidth(0), mScaling(scaling)
{
    mDecolation.clear();
    mHeightInPixels = 4000;
    mWidthInPixels = 1200;
    mLeftMargin = 0;
    mLogicalDpiX = mLogicalDpiY = 1200;
}

void GenericPagePrinter::preparePage(bool eject)
{
    int builtinMargin = 250;
    const int penWidth = 20;
    const int alternatingStripes = 20;

    setValues(eject);

    mPen->fillRect(0, 0, mWidthInPixels, mHeightInPixels-mLeftMargin, QColor(0xff, 0xff, 0xff));

    if (eject) mEndJobTrigger.clear();
    if (!mDecolation.isNull())
    {
        for (int i=0; i<mDecolation->mSeperator.mTriggers.count(); i++)
        {
            Trigger t = mDecolation->mSeperator.mTriggers[i];
            mEndJobTrigger.insert(t.line(), t);
        }
    }

    hOutDebug(1, "in pixels: " <<mWidthInPixels << " " << mHeightInPixels);
    hOutDebug(1, "left margin " << mLeftMargin);

    int stripe = (mHeightInPixels-(mMargin+mBottomMargin))/alternatingStripes*mScaling;

    if (mHeightInPixels > 0)
    {
        for (int i=mMargin+stripe; i<=mMargin+(alternatingStripes)*stripe; i+=2*stripe)
        {
            int barsR = mBarsColor[0];
            int barsG = mBarsColor[1];
            int barsB = mBarsColor[2];
            mPen->fillRect(mLeftMargin, i, mWidthInPixels-2*mLeftMargin, stripe, QColor(barsR, barsG, barsB));

            //        if (mStationery->mDecorated)
            //        {
            //            mPen->setPen(QPen(QColor(barsR-0x20, barsG-0x20, barsB-0x20), penWidth));
            //            mPen->drawLine(leftMargin,i,widthInPixels-leftMargin,i);
            //            mPen->drawLine(leftMargin,i+stripe,widthInPixels-leftMargin,i+stripe);
            //        }
        }
    }

    if (mStationery->mDecorated)
    {
        int barsR = mBarsColor[0];
        int barsG = mBarsColor[1];
        int barsB = mBarsColor[2];
        mPen->setPen(QPen(QColor(barsR, barsG, barsB), penWidth*(mScaling==1.0 ? 1.0 : 0.1)));
        mPen->drawRect(mLeftMargin, mMargin, mWidthInPixels-2*mLeftMargin, stripe*(alternatingStripes));//heightInPixels-leftMargin);
    }

    if (mStationery->mTractorFeedHoles)
    {
        QString pixmapStr(Environment::getIconsPath().c_str());
        pixmapStr +="/Hole.png";
        QPixmap pixmap(pixmapStr);
        hOutDebug(5, "hole width " << pixmap.width() << " " << pixmap.logicalDpiX() << " "  << pixmap.physicalDpiX());
        float gap = mLogicalDpiY/2;
        float holeStart = mLogicalDpiY/4 - builtinMargin;
        if (mScaling < 1)
        {
            gap = 40;
            holeStart = 20;
        }

        for (int holePos=holeStart; holePos <= mHeightInPixels; holePos += gap) // image is 200 pixels
        {
            //TODO: automatic scaling?
            if (mScaling < 1.0)
            {
                mPen->drawPixmap(50*mScaling, holePos, 15, 15, pixmap, 0,0,200,200);
            }
            else
            {
                mPen->drawPixmap(160, holePos, pixmap);
                mPen->drawPixmap(mWidthInPixels-160-200, holePos, pixmap);
            }
        }
    }
    //mPen->drawRect(0,0,mWidthInPixels, mHeightInPixels); //debug

    if (mLogoWidth == 0)
    {
        mLogo.fill(QColor(255,255,255,255));
        QPainter * logoPainter = new QPainter(&mLogo);

        const char * logo{"Printed With Hercules Studio"};
        logoPainter->setFont(QFont("Verdana", 110));
        logoPainter->setPen(QColor(mBarsColor[0], mBarsColor[1], mBarsColor[2]));
        logoPainter->drawText(0, logoPainter->fontMetrics().height() , logo);
        mLogoWidth = logoPainter->fontMetrics().width(logo);
        mLogoHeight = logoPainter->fontMetrics().height();
        logoPainter->end();
    }
    mPen->drawPixmap(mWidthInPixels-mLeftMargin-mLogoWidth, mHeightInPixels - mLogoHeight, mLogo);
}