@@ -288,6 +288,18 @@ RichElementNewLine* RichElementNewLine::create(int tag, const Color3B& color, ui
288
288
return nullptr ;
289
289
}
290
290
291
+ RichElementNewLine* RichElementNewLine::create (int tag, int quantity, const Color3B& color, uint8_t opacity)
292
+ {
293
+ RichElementNewLine* element = new RichElementNewLine (quantity);
294
+ if (element->init (tag, color, opacity))
295
+ {
296
+ element->autorelease ();
297
+ return element;
298
+ }
299
+ AX_SAFE_DELETE (element);
300
+ return nullptr ;
301
+ }
302
+
291
303
/* * @brief parse a XML. */
292
304
class MyXMLVisitor : public SAXDelegator
293
305
{
@@ -340,6 +352,8 @@ class MyXMLVisitor : public SAXDelegator
340
352
, italics(false )
341
353
, line(StyleLine::NONE)
342
354
, effect(StyleEffect::NONE)
355
+ , outlineSize(0 )
356
+ , shadowBlurRadius(0 )
343
357
{}
344
358
};
345
359
@@ -352,14 +366,15 @@ class MyXMLVisitor : public SAXDelegator
352
366
{
353
367
bool isFontElement;
354
368
RichText::VisitEnterHandler handleVisitEnter;
369
+ RichText::VisitExitHandler handleVisitExit;
355
370
};
356
371
typedef hlookup::string_map<TagBehavior> TagTables;
357
372
358
373
static TagTables _tagTables;
359
374
360
375
public:
361
376
explicit MyXMLVisitor (RichText* richText);
362
- virtual ~MyXMLVisitor ();
377
+ ~MyXMLVisitor () override ;
363
378
364
379
Color3B getColor () const ;
365
380
@@ -397,7 +412,8 @@ class MyXMLVisitor : public SAXDelegator
397
412
398
413
static void setTagDescription (std::string_view tag,
399
414
bool isFontElement,
400
- RichText::VisitEnterHandler&& handleVisitEnter);
415
+ RichText::VisitEnterHandler&& handleVisitEnter,
416
+ RichText::VisitExitHandler&& handleVisitExit = nullptr );
401
417
402
418
static void removeTagDescription (std::string_view tag);
403
419
@@ -573,6 +589,66 @@ MyXMLVisitor::MyXMLVisitor(RichText* richText) : _fontElements(20), _richText(ri
573
589
return make_pair (ValueMap (), richElement);
574
590
});
575
591
592
+ MyXMLVisitor::setTagDescription (" p" , false , nullptr ,
593
+ [] { return RichElementNewLine::create (0 , 2 , Color3B::WHITE, 255 ); });
594
+
595
+ constexpr auto headerTagEnterHandler = [](const ValueMap& tagAttrValueMap,
596
+ float defaultFontSize) -> std::pair<ValueMap, RichElement*> {
597
+ ValueMap attrValueMap;
598
+ if (tagAttrValueMap.find (" size" ) != tagAttrValueMap.end ())
599
+ {
600
+ attrValueMap[RichText::KEY_FONT_SIZE] = tagAttrValueMap.at (" size" ).asString ();
601
+ }
602
+ else
603
+ {
604
+ attrValueMap[RichText::KEY_FONT_SIZE] = defaultFontSize;
605
+ }
606
+
607
+ if (tagAttrValueMap.find (" color" ) != tagAttrValueMap.end ())
608
+ {
609
+ attrValueMap[RichText::KEY_FONT_COLOR_STRING] = tagAttrValueMap.at (" color" ).asString ();
610
+ }
611
+
612
+ if (tagAttrValueMap.find (" face" ) != tagAttrValueMap.end ())
613
+ {
614
+ attrValueMap[RichText::KEY_FONT_FACE] = tagAttrValueMap.at (" face" ).asString ();
615
+ }
616
+
617
+ attrValueMap[RichText::KEY_TEXT_BOLD] = true ;
618
+
619
+ return make_pair (attrValueMap, nullptr );
620
+ };
621
+
622
+ MyXMLVisitor::setTagDescription (
623
+ " h1" , true ,
624
+ [headerTagEnterHandler](const ValueMap& tagAttrValueMap) { return headerTagEnterHandler (tagAttrValueMap, 34 ); },
625
+ [] { return RichElementNewLine::create (0 , 2 , Color3B::WHITE, 255 ); });
626
+
627
+ MyXMLVisitor::setTagDescription (
628
+ " h2" , true ,
629
+ [headerTagEnterHandler](const ValueMap& tagAttrValueMap) { return headerTagEnterHandler (tagAttrValueMap, 30 ); },
630
+ [] { return RichElementNewLine::create (0 , 2 , Color3B::WHITE, 255 ); });
631
+
632
+ MyXMLVisitor::setTagDescription (
633
+ " h3" , true ,
634
+ [headerTagEnterHandler](const ValueMap& tagAttrValueMap) { return headerTagEnterHandler (tagAttrValueMap, 24 ); },
635
+ [] { return RichElementNewLine::create (0 , 2 , Color3B::WHITE, 255 ); });
636
+
637
+ MyXMLVisitor::setTagDescription (
638
+ " h4" , true ,
639
+ [headerTagEnterHandler](const ValueMap& tagAttrValueMap) { return headerTagEnterHandler (tagAttrValueMap, 20 ); },
640
+ [] { return RichElementNewLine::create (0 , 2 , Color3B::WHITE, 255 ); });
641
+
642
+ MyXMLVisitor::setTagDescription (
643
+ " h5" , true ,
644
+ [headerTagEnterHandler](const ValueMap& tagAttrValueMap) { return headerTagEnterHandler (tagAttrValueMap, 18 ); },
645
+ [] { return RichElementNewLine::create (0 , 2 , Color3B::WHITE, 255 ); });
646
+
647
+ MyXMLVisitor::setTagDescription (
648
+ " h6" , true ,
649
+ [headerTagEnterHandler](const ValueMap& tagAttrValueMap) { return headerTagEnterHandler (tagAttrValueMap, 16 ); },
650
+ [] { return RichElementNewLine::create (0 , 2 , Color3B::WHITE, 255 ); });
651
+
576
652
MyXMLVisitor::setTagDescription (" outline" , true , [](const ValueMap& tagAttrValueMap) {
577
653
// supported attributes:
578
654
// color, size
@@ -915,6 +991,15 @@ void MyXMLVisitor::endElement(void* /*ctx*/, const char* elementName)
915
991
{
916
992
popBackFontElement ();
917
993
}
994
+
995
+ if (tagBehavior.handleVisitExit != nullptr )
996
+ {
997
+ auto * richElement = tagBehavior.handleVisitExit ();
998
+ if (richElement)
999
+ {
1000
+ pushBackElement (richElement);
1001
+ }
1002
+ }
918
1003
}
919
1004
}
920
1005
@@ -974,14 +1059,12 @@ void MyXMLVisitor::pushBackElement(RichElement* element)
974
1059
975
1060
void MyXMLVisitor::setTagDescription (std::string_view tag,
976
1061
bool isFontElement,
977
- RichText::VisitEnterHandler&& handleVisitEnter)
1062
+ RichText::VisitEnterHandler&& handleVisitEnter,
1063
+ RichText::VisitExitHandler&& handleVisitExit)
978
1064
{
979
- hlookup::set_item (
980
- MyXMLVisitor::_tagTables, tag,
981
- TagBehavior{
982
- isFontElement,
983
- std::move (
984
- handleVisitEnter)}); // MyXMLVisitor::_tagTables[tag] = {isFontElement, std::move(handleVisitEnter)};
1065
+ // MyXMLVisitor::_tagTables[tag] = {isFontElement, std::move(handleVisitEnter), std::move(handleVisitExit)};
1066
+ hlookup::set_item (MyXMLVisitor::_tagTables, tag,
1067
+ TagBehavior{isFontElement, std::move (handleVisitEnter), std::move (handleVisitExit)});
985
1068
}
986
1069
987
1070
void MyXMLVisitor::removeTagDescription (std::string_view tag)
@@ -1536,9 +1619,11 @@ std::string RichText::stringWithColor4B(const ax::Color4B& color4b)
1536
1619
return std::string (buf, 9 );
1537
1620
}
1538
1621
1539
- void RichText::setTagDescription (std::string_view tag, bool isFontElement, VisitEnterHandler handleVisitEnter)
1622
+ void RichText::setTagDescription (std::string_view tag,
1623
+ bool isFontElement,
1624
+ VisitEnterHandler handleVisitEnter, VisitExitHandler handleVisitExit)
1540
1625
{
1541
- MyXMLVisitor::setTagDescription (tag, isFontElement, std::move (handleVisitEnter));
1626
+ MyXMLVisitor::setTagDescription (tag, isFontElement, std::move (handleVisitEnter), std::move (handleVisitExit) );
1542
1627
}
1543
1628
1544
1629
void RichText::removeTagDescription (std::string_view tag)
@@ -1659,7 +1744,9 @@ void RichText::formatText(bool force)
1659
1744
}
1660
1745
case RichElement::Type::NEWLINE:
1661
1746
{
1662
- addNewLine ();
1747
+ auto * newLineMulti = static_cast <RichElementNewLine*>(element);
1748
+
1749
+ addNewLine (newLineMulti->_quantity );
1663
1750
break ;
1664
1751
}
1665
1752
default :
@@ -1678,7 +1765,7 @@ void RichText::formatText(bool force)
1678
1765
addNewLine ();
1679
1766
for (ssize_t i = 0 , size = _richElements.size (); i < size; ++i)
1680
1767
{
1681
- RichElement* element = static_cast <RichElement*>( _richElements.at (i) );
1768
+ RichElement* element = _richElements.at (i);
1682
1769
switch (element->_type )
1683
1770
{
1684
1771
case RichElement::Type::TEXT:
@@ -1706,7 +1793,9 @@ void RichText::formatText(bool force)
1706
1793
}
1707
1794
case RichElement::Type::NEWLINE:
1708
1795
{
1709
- addNewLine ();
1796
+ auto * newLineMulti = static_cast <RichElementNewLine*>(element);
1797
+
1798
+ addNewLine (newLineMulti->_quantity );
1710
1799
break ;
1711
1800
}
1712
1801
default :
@@ -2049,11 +2138,15 @@ void RichText::handleCustomRenderer(ax::Node* renderer)
2049
2138
}
2050
2139
}
2051
2140
2052
- void RichText::addNewLine ()
2141
+ void RichText::addNewLine (int quantity )
2053
2142
{
2054
- _leftSpaceWidth = _customSize.width ;
2055
- _elementRenders.emplace_back ();
2056
- _lineHeights.emplace_back ();
2143
+ do
2144
+ {
2145
+ _leftSpaceWidth = _customSize.width ;
2146
+ _elementRenders.emplace_back ();
2147
+ _lineHeights.emplace_back ();
2148
+ }
2149
+ while (--quantity > 0 );
2057
2150
}
2058
2151
2059
2152
void RichText::formatRenderers ()
0 commit comments