New Symbolic Color in Pango Span Text - c++

First time poster; long time admirer of the Stack Overflow angels.
I'm having an issue with colors in span text that are controlled by Pango.
Long Version:
I'm updating an old UI program which has C++ code guts with GTK, XML (written by Glade), and an RC stylesheet handling the graphics. Some of our colored markup text is hard-coded in the XML. Some of it is dynamically set in the C++ code.
The problem is, that when the program runs on our older systems, the color referenced by span text as 'green' shows up as #00FF00. On our newer systems, 'green' is showing up as #008000.
Example of code printing to a label widget:
gtk_label_set_markup((GtkLabel *) TitleBarLabel, "<span color='green'>Orbital Cannon Positioning</span>");
I'm fairly certain that Pango is in control of the span text markup. I found that the difference between the greens is exactly the difference between X11 and W3C color lists (https://en.wikipedia.org/wiki/X11_color_names#Clashes_between_web_and_X11_colors).
It seems that our old systems are using X11 and our new ones are using W3C, which makes sense.
I could just replace all instances of 'green' with '#00FF00' but if we wanted to change the colors in the future, we'd have to go through the whole thing again. I'd much rather have the colors changeable through a stylesheet instead of baked into the code.
C++ Code:
GtkWidget * TitleBarLabel;
TitleBarLabel = GTK_WIDGET (get_builder_object (builder, "TitleBarLabel"));
gtk_label_set_markup((GtkLabel *) TitleBarLabel, "<span color='#00FF00'>Death Ray Power Status</span>");
I can create a GdkColor at run-time and gdk_color_parse it with values from a config file, and then use gtk_widget_modify_text() to apply the color to the label widgets. But then that doesn't work for all of the hard-coded span text in the XML. Also, we have pleanty of labels with bits of text colored differently inside the same line.
C++ Code:
GdkColor pass_color;
gdk_color_parse("#00FF00", &pass_color);
gtk_widget_modify_text(TitleBarLabel, GTK_STATE_NORMAL, &pass_color);
I can make a style in my RC file for each color and link every single label that would use that color at run-time. But we'd have to remove all markup coloring and add lots of code for grabbing widgets that we never bothered with before and code for setting names of widgets instead of just printing to them with new span text. It gets the desired result of having the colors changeable in a stylesheet but it's a massive undertaking and it's not intuitive for our veteran engineers who are used to using the color attributes.
RC File:
style "pass_color"
{
fg[NORMAL] = #00FF00
}
widget "*TitleBarLabel_Pass" style "pass_color"
C++ Code:
gtk_widget_set_name(TitleBarLabel, "TitleBarLabel_Pass");
Short Version:
Ideally, I would like to be able to make a new color at run-time that we can link with span text in such faction:
<span color='MyNewColor'>Weather Manipulation Settings</span>
Or maybe even create a new tag that applies specific attributes, like:
<span><MyNewColor>Shark Tank pH Balance</MyNewColor></span>
But I doubt that's possible.
I tried playing around with pango_attr_type_register(), pango_attr_foreground_new(), and friends, but I couldn't figure out how attributes work of if they could even do what I thought they did. After much research, it looks like an 'attribute' is just a one-time setting on a single string of text. And not a new value that can be called in line with span text, as I hoped.
Is anything like this remotely possible without rebuilding all of Pango?
Is there a different work around that would get me a stylesheet like setup?
At this point, I'm open to suggestions.
Version Specs:
Computers showing green as #00FF00
OS: Linux Slackware 13.37 and below
GTK: 2.24.4
Pango: 1.28.4
Computers showing green as #008000
OS: Linux Slackware 14.1
GTK: 2.24.20
Pango: 1.34.1

If you are able to use GTK 3.x, I would suggest doing that, where this is much easier to do using CSS. There is even a way to use multiple CSS styles for different regions in the same label, though it is awkward.
In GTK 2, as you noted, you can reference widgets by their name property in your RC file:
widget "shark-tank-ph-label" style "green-text"
style "green-text" {
text[NORMAL] = #008000
}
I would recommend taking this approach even if it's not what you're used to. Refactoring once to remove the hardcoded colors from your labels will make it much easier the next time you have to change something like this, and will also make your code closer to how things would work in GTK 3.x should you decide to make a port in the future.

Related

papaja: Changing font sizes and faces for code listings and R output

Based on the answer to this question, I was able to get 2-column papaja with listings wrapping (rather than overflowing column width). But the listings package turns off various features that help code listings and R output stand out relative to the main text.
A simple solution would be if I could globally change the font faces and/or sizes selectively for code and R output. Is there a way to do that in papaja? I haven't been able to figure this out from papaja or Rmarkdown documentation. Thank you!
When you use the listings package in a papaja (or bookdown) document, what is technically happening is that all code is wrapped into an lstlisting LaTeX environment that comes with its own capabilities of customizing code appearance. Hence, you don't see the syntax highlighting that you would otherwise see if you would not use the listings package. The documentation of the listings package with instructions how to style your code can be found here.
To make use of this, you can extend the YAML header of your papaja document like this:
documentclass : "apa6"
classoption : "jou"
output :
papaja::apa6_pdf:
pandoc_args: --listings
header-includes:
- \lstset{breaklines=true,language=R,basicstyle=\tiny\ttfamily,frame=trB,commentstyle=\color{darkgray}\textit}
Here, I first specify the code's language, and use a tiny monospace font. With frame, I add a frame around the code block, and with commentstyle I set comments in italic and gray.

How to check installed fonts styles?

I need a list of all installed fonts in the client machine (Always Windows) that contain the styles bold, italic and bold italic. Is there a function for that?
I'm already able to list all installed fonts with EnumFontFamiliesEx and i suppose that is possible to filter that list, but i'm looking for a "better way" :)
Thanks!
PS: I'm using C++ with MFC.
EDIT:
For fonts that doesn't have these styles Windows can "fake" that behavior (force a font look bold or italic), but i need to know which fonts really have these styles.
As you are using "EnumFontFamiliesEx",the call back function recieves the structure LOGFONT....
LOGFONT has two variables lfWeight and lfItalic.
Use those two variables to check if the enumerated font has style or not.
if lfWeight value is 0 (FW_DONTCARE) and lfItalic is false, you can consider this do not have any style.
Or if you want to be very specific, for example, you want to consider fonts with only Bold and Regular, then you can validate, if lfWeight has value from {400 (REGULAR), 600 (BOLD), 700 (BOLD), 800 (BOLD)}
Below link has all the details.
https://msdn.microsoft.com/en-us/library/windows/desktop/dd145037(v=vs.85).aspx

Losing stylesheet setup after applying font change

In my code I have widgets and change their styles the following way:
resultGroupBox->setStyleSheet("background-color:#7979ec;");
And later in code:
resultGroupBox->setStyleSheet("font: bold 14px\"Verdana\"");//this is done by function (set_fonts());
After the second style is applied the first is lost. I wonder if there is a way to deal with this (I need the both the fonts and the background), except for setting background-color and fonts in the same command.
It looks like your function is "setStyleSheet", isn't there a function to "AddStyle"?
Even better is adding a class instead of a style. For example with the jQuery addClass function. See https://api.jquery.com/addclass/

How to set borders and other styles of a plugin object from JSAPI side?

I have this::
FB::DOM::ElementPtr _element=m_host->getDOMWindow()->getDocument()->getBody()->getElementById("plugin0");
I got the element(i.e. object tag of the plugin that i wanted) by ID. It's compiling. I now want to SET its property from the JSAPI side...like border color style and width....
I went through this page . I could find only 1 method "setInnerHtml"...which sets something. What should i pass in its argument...?it has std::string type...so that I can manipulate the plugin's document. Any ideas...
Basically I want to set the attribute of a tag from PluginAPI side.....
Honestly? You'd be much better off putting the plugin in a div at 100%x100% and then managing the border of the div. For something like this I'd probably just use:
m_host->evaluateJavascript("document.getElementById('pluginCont').style.border = '1px solid black';");
That'll be the easiest. You could also look at the DOM abstraction code and add some tools for managing CSS; note that on IE you may need to use special activex methods to do this, which is why I dont' recommend just doing it through getDOMElement() (which is a shorthand, btw, for the long code you have in your example)

How to load qt linguist dynamically changed label text

In my project i'm trying to use qt linguist. When i change the language from English to Turkish, it is working all constant label.
But some labels i m loading them dynamically according to scenario of use cases.
Whatever i do with qt linguist, it doest workthe texts of these label.
How can i get rid of this problem?
Any help will be apprecialted
Qt has a guide to internationalization, which includes the basic information: to wrap your string in a tr function call.
label->setText( tr( "Hello, World!" ) );
In addition to this, if you want the language to change on the fly, you'll need to identify when the context has changed, and update your labels appropriately. Unfortunately, I can't easily put my hands on the signal that indicates when to do so.