1010 ******************************************************************************/
1111
1212#include " qt_renderer.hpp"
13+ #include " Freetype/tt_face.hpp"
14+ #include " Freetype/unicode_font.hpp"
1315#include " analyze.hpp"
1416#include " file.hpp"
1517#include " frame.hpp"
1618#include " image_files.hpp"
19+ #include " picture.hpp"
20+ #include " qimage.h"
21+ #include " qt_picture.hpp"
1722#include " qt_utilities.hpp"
1823#include " scheme.hpp"
24+ #include " unicode.hpp"
1925
2026#include < QObject>
2127#include < QPaintDevice>
2228#include < QPainterPath>
2329#include < QPixmap>
30+ #include < QSvgRenderer>
2431#include < QWidget>
2532
2633/* *****************************************************************************
@@ -549,6 +556,10 @@ qt_renderer_rep::draw_bis (int c, font_glyphs fng, SI x, SI y) {
549556
550557void
551558qt_renderer_rep::draw (int c, font_glyphs fng, SI x, SI y) {
559+ if (is_emoji_character (c)) {
560+ draw_emoji (c, fng, x, y);
561+ return ;
562+ }
552563 if (pen->get_type () == pencil_brush) {
553564 draw_bis (c, fng, x, y);
554565 return ;
@@ -641,6 +652,74 @@ qt_renderer_rep::draw (const QFont& qfn, const QString& qs, SI x, SI y,
641652 painter->resetTransform ();
642653}
643654
655+ picture
656+ svg_string_to_picture (string svg_data, int w, int h) {
657+ if (N (svg_data) == 0 ) {
658+ // Return null if no SVG data
659+ return picture ();
660+ }
661+
662+ // Create QByteArray from SVG string data
663+ QByteArray svg_bytes (as_charp (svg_data), N (svg_data));
664+
665+ // Create SVG renderer from the data
666+ QSvgRenderer renderer (svg_bytes);
667+
668+ if (!renderer.isValid ()) {
669+ // Return null if SVG is invalid
670+ return picture ();
671+ }
672+
673+ // Create QImage to render SVG into
674+ QImage image (w, h, QImage::Format_ARGB32);
675+ image.fill (Qt::transparent);
676+
677+ // Render SVG to the image
678+ QPainter painter (&image);
679+ renderer.render (&painter);
680+ painter.end ();
681+
682+ // Return the picture created from QImage
683+ return qt_picture (image, 0 , 0 );
684+ }
685+
686+ void
687+ qt_renderer_rep::draw_emoji (int char_code, font_glyphs fn, SI x, SI y) {
688+
689+ // Cast to TrueType font glyphs representation
690+ auto tt_font= static_cast <tt_font_glyphs_rep*> (fn.rep );
691+ if (is_nil (tt_font->face ) || is_nil (tt_font->face ->svg_table )) {
692+ return ;
693+ }
694+
695+ // Get glyph ID for the emoji character
696+ int glyph_id= ft_get_char_index (tt_font->face ->ft_face , char_code);
697+ if (glyph_id <= 0 ) {
698+ return ;
699+ }
700+
701+ // Retrieve SVG data for the glyph
702+ string svg_data= tt_font->face ->svg_table ->get_svg_from_glyphid (glyph_id);
703+ if (N (svg_data) == 0 ) {
704+ return ;
705+ }
706+
707+ // Calculate emoji size
708+ SI xo, yo;
709+ glyph pre_gl= fn->get (char_code);
710+ glyph gl = shrink (pre_gl, std_shrinkf, std_shrinkf, xo, yo);
711+ int w= gl->width , h= gl->height ;
712+
713+ // Create picture from SVG data
714+ picture emoji_picture= svg_string_to_picture (svg_data, w, h);
715+ if (is_nil (emoji_picture)) {
716+ return ;
717+ }
718+
719+ // Draw the emoji picture at the specified position
720+ draw_picture (emoji_picture, x, y, 255 );
721+ }
722+
644723/* *****************************************************************************
645724 * main qt renderer
646725 ******************************************************************************/
@@ -904,4 +983,4 @@ qt_shadow_renderer_rep::get_shadow (renderer ren, SI x1, SI y1, SI x2, SI y2) {
904983 else {
905984 shadow->painter ->setClipRect (QRect ());
906985 }
907- }
986+ }
0 commit comments