summaryrefslogtreecommitdiff
path: root/utils/wpseditor/gui/src/qwpsdrawer_static.cpp
blob: bf94d28a5aa6328262c9521f2c99524cc67e0cb6 (plain)
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
#include "qwpsdrawer.h"
#include <QPainter>
#include <QFile>
#include <QFileInfo>
#include "utils.h"

void QWpsDrawer::putsxy(int x, int y, const unsigned char *str) {
    QPainter p(pix);
    viewport_api avp;
    api.get_current_vp(&avp);
    p.setPen(Qt::gray);


    QFont font("times",avp.fontheight,QFont::Bold);
    p.setFont(font);
    p.drawText(x+avp.x,y + avp.fontheight + avp.y,(char*)str);
}
void QWpsDrawer::transparent_bitmap_part(const void *src, int src_x, int src_y,
        int stride, int x, int y, int width, int height) {
    QImage img;
    img.load((char*)src);
    DEBUGF2("transparent_bitmap_part(const void *src=%s, int src_x=%d, int src_y=%d,int stride=%d, int x=%d, int y=%d, int width=%d, int height=%d",(char*)src,src_x, src_y,stride, x, y, width, height);
    QPainter p(pix);
    QPoint target(x,y);
    QRectF source(src_x, src_y, width, height);

    QImage pink = img.createMaskFromColor(qRgb(255,0,255),Qt::MaskOutColor);
    img.setAlphaChannel(pink);

    p.drawImage(target, img, source);
}
void QWpsDrawer::bitmap_part(const void *src, int src_x, int src_y,
                             int stride, int x, int y, int width, int height) {
    transparent_bitmap_part(src,src_x,src_y,stride,x,y,width,height);
}
void QWpsDrawer::drawpixel(int x, int y) {
    QPainter p(pix);
    p.setPen(Qt::blue);
    p.drawPoint(x,y);
}
void QWpsDrawer::fillrect(int x, int y, int width, int height) {
    QPainter p(pix);
    DEBUGF2("fillrect(int x=%d, int y=%d, int width=%d, int height=%d)\n",x, y, width, height);
    p.setPen(Qt::green);
}
void QWpsDrawer::hline(int x1, int x2, int y) {
    QPainter p(pix);
    p.setPen(Qt::black);
    p.drawLine(x1,y,x2,y);
}
void QWpsDrawer::vline(int x, int y1, int y2) {
    QPainter p(pix);
    p.setPen(Qt::black);
    p.drawLine(x,y1,x,y2);
}
bool QWpsDrawer::load_wps_backdrop(char* filename) {
    DEBUGF2("load backdrop: %s", filename);
    QFile file(filename);
    QFileInfo info(file);
    file.copy(mTmpWpsString+"/"+info.fileName());
    backdrop.load(filename);
    return true;
}

int QWpsDrawer::read_bmp_file(const char* filename,int *width, int *height) {
    QImage img;

    QFile file(filename);
    QFileInfo info(file);
    file.copy(mTmpWpsString+"/"+info.fileName());

    img.load(filename);
    //qDebug()<<"QWpsDrawer::read_bmp_file"<<img.width()<<img.height();
    *width = img.width();
    *height = img.height();
    return 1;
}