add symbol JKQTPFilledCharacterSymbol

This commit is contained in:
jkriege2 2022-09-06 11:57:58 +02:00
parent 2831dcbfb5
commit f6def4b9d1
8 changed files with 78 additions and 12 deletions

View File

@ -43,7 +43,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
<li>NEW: made resize-timer status accessible from outside via JKQTPlotter::isResizeTimerRunning() </li>
<li>NEW: made it's delay a global static variable that can be set and red with JKQTPlotter::setGlobalResizeDelay() and JKQTPlotter::getGlobalResizeDelay()</li>
<li>NEW: Using JKQTMathText::useGuiFonts() for FONT rendering by default</li>
<li>NEW: added the option to draw a character from a font as symbol (<code>JKQTPCharacterSymbol+QChar('C').unicode()</code>)</li>
<li>NEW: added the option to draw a character from a font as symbol (<code>JKQTPCharacterSymbol+QChar('C').unicode()</code> and <code>JKQTPFilledCharacterSymbol+QChar('C').unicode()</code>)</li>
</ul></li>
<li>JKQTMathText:<ul>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 457 B

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -92,13 +92,19 @@ QString JKQTPGraphSymbols2String(JKQTPGraphSymbols pos) {
case JKQTPCirclePeace: return "symbol_circle_peace";
case JKQTPSymbolCount: JKQTPGraphSymbols2String(JKQTPMaxSymbolID);
case JKQTPCharacterSymbol:
break;
case JKQTPFilledCharacterSymbol:
break;
}
if (pos>=JKQTPCharacterSymbol && pos<=JKQTPCharacterSymbol+0xFF) {
if (pos>=JKQTPCharacterSymbol && pos<=JKQTPCharacterSymbol+0xFFFF) {
QString s=QString::number(pos-JKQTPCharacterSymbol,16);
while (s.size()<4) s="0"+s;
return "symbol_char"+s;
}
if (pos>=JKQTPFilledCharacterSymbol && pos<=JKQTPFilledCharacterSymbol+0xFFFF) {
QString s=QString::number(pos-JKQTPFilledCharacterSymbol,16);
while (s.size()<4) s="0"+s;
return "symbol_filled_char"+s;
}
return "";
}
@ -169,11 +175,16 @@ QString JKQTPGraphSymbols2NameString(JKQTPGraphSymbols pos) {
case JKQTPMale: return QObject::tr("male");
case JKQTPCirclePeace: return QObject::tr("circled peace");
case JKQTPSymbolCount: JKQTPGraphSymbols2NameString(JKQTPMaxSymbolID);
case JKQTPCharacterSymbol: break;
case JKQTPCharacterSymbol:
case JKQTPFilledCharacterSymbol:
break;
}
if (pos>=JKQTPCharacterSymbol && pos<=JKQTPCharacterSymbol+0xFF) {
if (pos>=JKQTPCharacterSymbol && pos<=JKQTPCharacterSymbol+0xFFFF) {
return QObject::tr("character")+" '"+QChar(static_cast<uint16_t>(pos-JKQTPCharacterSymbol))+"'";
}
if (pos>=JKQTPFilledCharacterSymbol && pos<=JKQTPFilledCharacterSymbol+0xFFFF) {
return QObject::tr("filled character")+" '"+QChar(static_cast<uint16_t>(pos-JKQTPFilledCharacterSymbol))+"'";
}
return "";
}
JKQTPGraphSymbols String2JKQTPGraphSymbols(const QString& pos) {
@ -256,6 +267,18 @@ JKQTPGraphSymbols String2JKQTPGraphSymbols(const QString& pos) {
if (posT.startsWith("symbol_char")) {
return JKQTPCharacterSymbol+posT.mid(11).toUInt(nullptr,16);
}
if (posT.startsWith("symbol_fillcharsym") && posT.size()>18) {
return JKQTPFilledCharacterSymbol+posT[18].unicode();
}
if (posT.startsWith("fillcharsym") && posT.size()>11) {
return JKQTPFilledCharacterSymbol+posT[11].unicode();
}
if (posT.startsWith("filled_char")) {
return JKQTPFilledCharacterSymbol+posT.mid(11).toUInt(nullptr,16);
}
if (posT.startsWith("symbol_filled_char")) {
return JKQTPFilledCharacterSymbol+posT.mid(18).toUInt(nullptr,16);
}
return JKQTPNoSymbol;
}

View File

@ -138,7 +138,13 @@ enum JKQTPGraphSymbols: uint64_t {
JKQTPMaxSymbolID=JKQTPSymbolCount-1, /*!< \brief points to the last available symbol, can be used to iterate over all symbols: <code>for (int i=0; i<=static_cast<int>(JKQTPMaxSymbolID); i++) { JKQTPGraphSymbols s=static_cast<JKQTPGraphSymbols>(i); ... }</code> */
JKQTPDefaultSymbol=JKQTPCross, /*!< \brief a default symbol used for plotting */
JKQTPCharacterSymbol=0x100, /*!< \brief you can use any character from a QFont by supplying \c JKQTPCharacterSymbol+QChar('').unicode() as JKQTPGraphSymbols \image html symbols/symbol_char_at.png "generated by JKQTPCharacterSymbol+QChar('@').unicode()" */
JKQTPCharacterSymbol=0x100, /*!< \brief draw a font-character as symbol with defined fill-brush (taken from symbol-color), you can use any character from a QFont by supplying \c JKQTPCharacterSymbol+QChar('').unicode() as JKQTPGraphSymbols
\image html symbols/symbol_char_at.png "generated by JKQTPCharacterSymbol+QChar('@').unicode()"
\image html symbols/symbol_char_club.png "generated by JKQTPCharacterSymbol+QChar(0x2663).unicode()" */
JKQTPFilledCharacterSymbol=JKQTPCharacterSymbol+0xFFFF+0xF, /*!< \brief draw a font-character as symbol with defined outline-pen and fill-brush, you can use any character from a QFont by supplying \c JKQTPFilledCharacterSymbol+QChar('').unicode() as JKQTPGraphSymbols
\image html symbols/symbol_filled_char_at.png "generated by JKQTPFilledCharacterSymbol+QChar('@').unicode()"
\image html symbols/symbol_filled_char_club.png "generated by JKQTPFilledCharacterSymbol+QChar(0x2663).unicode()"
*/
};
inline JKQTPGraphSymbols operator+(JKQTPGraphSymbols a, uint8_t b) {
@ -506,6 +512,8 @@ inline void JKQTPPlotSymbol(TPainter& painter, double x, double y, JKQTPGraphSym
p.setCapStyle(Qt::FlatCap);
QPen pDescaled=p;
pDescaled.setWidthF(pDescaled.widthF()/symbolSize);
QFont fDescaled=symbolFont;
fDescaled.setPointSizeF(fDescaled.pointSizeF()/symbolSize);
const QBrush b=QBrush(fillColor, Qt::SolidPattern);
@ -864,6 +872,7 @@ inline void JKQTPPlotSymbol(TPainter& painter, double x, double y, JKQTPGraphSym
case JKQTPNoSymbol:
case JKQTPSymbolCount:
case JKQTPCharacterSymbol:
case JKQTPFilledCharacterSymbol:
break;
}
if (symbol>=JKQTPCharacterSymbol && symbol<=JKQTPCharacterSymbol+0xFFFF) {
@ -883,12 +892,27 @@ inline void JKQTPPlotSymbol(TPainter& painter, double x, double y, JKQTPGraphSym
//painter.setPen(QColor("red"));
//painter.drawRect(tbr);
//painter.drawEllipse(QPointF(0,0),2,2);
painter.setBrush(QColor(Qt::transparent));
painter.setPen(pDescaled.color());
painter.setFont(symbolFont);
painter.drawText(0.0,0.0,ch);
painter.setBrush(color);
painter.setPen(Qt::NoPen);
QPainterPath path;
path.addText(0,0,symbolFont, ch),
painter.drawPath(path);
}
if (symbol>=JKQTPFilledCharacterSymbol && symbol<=JKQTPFilledCharacterSymbol+0xFFFF) {
symbolFont.setStyleStrategy(QFont::PreferDefault);
const QChar ch(static_cast<uint16_t>(symbol-JKQTPFilledCharacterSymbol));
const QFontMetricsF fm(symbolFont);
const QRectF tbr=fm.tightBoundingRect(ch);
const double scale=symbolSize/qMax(tbr.width(), tbr.height());
painter.setPen(p);
painter.translate(QPointF(x,y));
painter.scale(scale,scale);
painter.translate(-tbr.center());//QPointF(-tbr.width()/2.0,-tbr.height()/2.0)+QPointF(tbr.x(),tbr.y()));
painter.setBrush(b);
QPainterPath path;
path.addText(0,0,symbolFont, ch),
painter.drawPath(path);
}
}
template <class TPainter>

View File

@ -79,13 +79,32 @@ int main(int argc, char* argv[])
JKQTPEnhancedPainter p;
startPainting(img, p, iconsize, backgroundColor);
JKQTPPlotSymbol(p, iconsize/2,iconsize/2,s,iconsize-4,2,QColor("blue"), QColor("salmon").lighter(120),QGuiApplication::font().family());
p.setPen(QPen(QColor("green"),0.5));
//p.drawRect(2,2,iconsize-4,iconsize-4);
stopPaintingAndSave(img, p, outputDir.absoluteFilePath(JKQTPGraphSymbols2String(s)+".png"));
}
QImage img;
JKQTPEnhancedPainter p;
startPainting(img, p, iconsize, backgroundColor);
JKQTPPlotSymbol(p, iconsize/2,iconsize/2,JKQTPCharacterSymbol+QChar('@').unicode(),iconsize-4,2,QColor("blue"), QColor("blue").lighter(),QGuiApplication::font().family());
JKQTPPlotSymbol(p, iconsize/2,iconsize/2,JKQTPCharacterSymbol+QChar('@').unicode(),iconsize-4,1,QColor("blue"), QColor("salmon").lighter(120),QGuiApplication::font().family());
p.setPen(QPen(QColor("green"),0.5));
//p.drawRect(2,2,iconsize-4,iconsize-4);
stopPaintingAndSave(img, p, outputDir.absoluteFilePath("symbol_char_at.png"));
startPainting(img, p, iconsize, backgroundColor);
JKQTPPlotSymbol(p, iconsize/2,iconsize/2,JKQTPFilledCharacterSymbol+QChar('@').unicode(),iconsize-4,0.5,QColor("blue"), QColor("salmon").lighter(120),QGuiApplication::font().family());
p.setPen(QPen(QColor("green"),0.5));
//p.drawRect(2,2,iconsize-4,iconsize-4);
stopPaintingAndSave(img, p, outputDir.absoluteFilePath("symbol_filled_char_at.png"));
startPainting(img, p, iconsize, backgroundColor);
JKQTPPlotSymbol(p, iconsize/2,iconsize/2,JKQTPCharacterSymbol+QChar(0x2663).unicode(),iconsize-4,1,QColor("blue"), QColor("salmon").lighter(120),QGuiApplication::font().family());
p.setPen(QPen(QColor("green"),0.5));
//p.drawRect(2,2,iconsize-4,iconsize-4);
stopPaintingAndSave(img, p, outputDir.absoluteFilePath("symbol_char_club.png"));
startPainting(img, p, iconsize, backgroundColor);
JKQTPPlotSymbol(p, iconsize/2,iconsize/2,JKQTPFilledCharacterSymbol+QChar(0x2663).unicode(),iconsize-4,0.5,QColor("blue"), QColor("salmon").lighter(120),QGuiApplication::font().family());
p.setPen(QPen(QColor("green"),0.5));
//p.drawRect(2,2,iconsize-4,iconsize-4);
stopPaintingAndSave(img, p, outputDir.absoluteFilePath("symbol_filled_char_club.png"));
}
if (listlinedecorators) {