MCPcopy Create free account
hub / github.com/Robotips/uConfig / widthCompute

Function widthCompute

src/test/kicadfont/textwidth.cpp:10–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8#include <QStringList>
9
10void widthCompute()
11{
12 //
13 /*QString namePin, namePin2;
14 namePin.append('|');
15 for (char c=32; c<=125; c++)
16 {
17 namePin.append(c);
18 namePin.append('|');
19 namePin2.append(c);
20 }
21 component->addPin(new Pin(namePin, "A"));
22 component->addPin(new Pin(namePin2, "B"));*/
23
24 QImage imgText("textPin.png");
25 QImage imgOne("textPipe.png");
26 int y = 67;
27
28 QPixmap pix(imgText.width(), imgOne.height());
29 QPainter painter(&pix);
30 painter.setBrush(QColor(255, 0, 0, 64));
31 painter.drawImage(QPoint(0, 0), imgText, QRect(0, y, imgText.width(), imgOne.height()));
32 qDebug() << imgText.width();
33
34 QStringList widths;
35 int oldX = 0;
36 char c = 32;
37 for (int x=0; x<imgText.width()-imgOne.width(); x++)
38 {
39 int conv = 0;
40 for (int x0=0; x0<imgOne.width(); x0++)
41 {
42 for (int y0=0; y0<imgOne.height(); y0++)
43 {
44 conv += qAbs(qGray(imgText.pixel(x0+x, y0+y)) - qGray(imgOne.pixel(x0, y0)));
45 }
46 }
47 if (conv < 5000 && x-oldX-imgOne.width()>5)
48 {
49 widths.append(QString::number(x-oldX-imgOne.width()));
50 qDebug() << c++ << x << conv << x-oldX-imgOne.width();
51 painter.drawRect(x, 0, imgOne.width()-1, imgOne.height()-1);
52 oldX = x;
53 }
54 }
55 pix.save("test.png");
56
57 qDebug()<<widths.join(", ");
58}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected