Closed d47081 closed 1 month ago
You think i can escape by default ?
I don't understand where is problem coming from, tried this code and everything work
<?php
\Gtk::init();
$win = new \GtkWindow();
$win->set_default_size(300, 200);
$label = new \GtkLabel;
$label->set_use_markup(true);
$label->set_markup("๐ง๏ธ ๐๐");
$win->add($label);
$win->show_all();
\Gtk::main();
As my issue happened on browsing different pages, usually contain lot of text, I can't understand where is exactly wrong/unescaped char by this debug message
(php:76903): Gtk-WARNING **: 04:44:57.040: Failed to set text >> ORIGINAL BODY GOES HERE
but I wish to try any GTK escape method, and implement it by the way
You think i can escape by default ?
not sure set_markup
escapes text by default, because currently I'm using PHP htmlspecialchars
to resolve special chars issues. but sometimes, some pages contain unsupported raw input that drop warning in terminal
i got , but you think i can escape everytime with g_markup_escape_text
or expose the method to espace if you want?
https://docs.gtk.org/glib/func.markup_escape_text.html
gchar*
g_markup_escape_text (
const gchar* text,
gssize length
)
it should return escaped text or not?
$label->set_markup(
markup_escape_text("๐ง๏ธ ๐๐") // something like this
);
I have opened this feature request because not found in php-gtk3 sources, so thoughts to add and try. Suppose some native htmlspecialchars
alternative should be available in GTK for special chars escape operations
Your code works fine here
You need show what?
I think g_markup_escape_text
will escape tags. For example, if you need to show <test>
in your text
By the fact I'm using following code to escape special chars in markup, then append tags: https://github.com/YGGverse/Yoda/blob/main/src/Entity/Browser/Container/Page/Content/Gemtext.php
In fact just want to replace htmlspecialchars
withmarkup_escape_text
but seems method not available in php-gtk3
Current solution mostly works (to convert gemtext to pango), but sometimes (maybe when page contain emoji) I have alert in terminal that markup given to set_markup
contain errors or unescaped chars and could not be rendered properly.
Today can't catch this issue, will try to reproduce this problem later from laptop where I have data URL bookmarked.
Finally I have added this feature by PR https://github.com/scorninpc/php-gtk3/pull/135
I see lot of useful function there for next integrations https://docs.gtk.org/glib/index.html#functions
suppose it's better than use php htmlspecialchars
not adapted for pango
Seems I need now (at least to try) https://docs.gtk.org/glib/func.utf8_make_valid.html https://docs.gtk.org/glib/func.utf8_normalize.html
and some others because native php functions is not about gtk tasks to find alternatives there all the time
and I vote for Glib namespace, because:
That's not for right now but thoughts, and thoughts about this one API #151 I think these features usage is developers responsibility, not php-gtk provider problem to not implement them.
I think you dont complete understand escape methods, encodes, etc
this all is a pattern to manipulate strings. methods and languages are irrelevants
in this case, php has advances to use iconv and mb_string
you can convert any encoded string to utf8 with iconv(mb_detect_encoding($text, mb_detect_order(), true), "UTF-8", $text);
for example
anyway, if you want to implement, go aread
Thanks, I knew this method. Just opinion.
Tried iconv
method but no luck
Here is my warning:
(php:38452): Pango-WARNING **: 21:45:40.966: pango_layout_set_markup_with_accel: Error on line 1 char 52: Invalid UTF-8 encoded text in name โ not valid โ๐ฅ Docked: 1464 ยท ๐ฌ Logs: 6430 ยท \xf0\x9f\x95โ
I'm getting warning at this construction:
$layout = new PangoLayout(
(new GtkDrawingArea)->create_pango_context()
);
$layout->set_markup(
$markup, // iconv does not helps
mb_strlen(
$markup,
self::ENCODING
)
);
imho, sometimes encoding subject is harder than looks like. suppose the problem with emoji format version not supported yet or unknown by php function
When I provide this markup to GtkLabel
->set_markup
- no any problem, I believe that's because it uses native Glib
functions with results expected by widgets, where php uses own versions.
Just one of possible reasons.
Seems this method wanted to escape data for
Label::set_markup
properly https://docs.gtk.org/glib/func.markup_escape_text.htmlI had used PHP function
htmlspecialchars
butExample text too long, but supporse it could be any char of these: