Change font face/size of the top GTKWindow? - gtk3

I'm trying to use .NET Core GTK. For WinForms, we can select the form, and then click the Font property to change the font face or size within the Form designer. If we change the top form's font, it is applied to all the child controls on the form.
I wanted to do similar thing in Glade, but I cannot find a "Font" GUI in any of the attribute tabs.
Is this possible with GTK#?
If so, can it be done within Glade?
If the answer to 2 is no, can it be done in the code?

Yes this is possible in both GTK and Glade, although some code will be required to change all the forms font.
In GTK you will be using the GtkFontChooserWidget. This should let you choose between fonts.
In Glade, when you are using the attributes tab you are able to change font size with the Scale attribute. I haven't yet figured out how to change the actual font through those attributes yet. Thankfully there is a workaround. Instead of using Attributes, use Markup. Markup works just fine for both font size and font style.
Markup Example
<span font='36' face='Georgia'>Markup</span>
Assuming you are using a GtkComboBoxText to list possible fonts and button for selecting, you would just need a handler that would go through each of the labels and change the font to the designated one.
def when_visible(window):
"""
This is where per-window initialization takes place.
Values to be displayed are populated into their widgets.
"""
global FONT_FACE
name = Gtk.Buildable.get_name(window) # Window currently on
if 'font_select_screen' = name:
font = BUILDER.get_object('fontEntryCombo')
FONT_FACE = font.get_active_text()
elif 'random_screen' = name:
label1_text = "<span font='36' face='{}'>Label</span>".format(FONT_FACE)
label1 = BUILDER.get_object('label1')
label1.set_markup(label1_text)

Related

Custom font with dynamic type in interface builder

I have several views in my Storyboard which have UILabels. These labels are set to Automatically Adjusts Font and use text styles like Body or Headline.
I know there is a programmatic approach as such:
https://useyourloaf.com/blog/using-a-custom-font-with-dynamic-type/
let label = UILabel()
label.font = scaledFont.font(forTextStyle: textStyle)
label.adjustsFontForContentSizeCategory = true
However, given that I have already laid out my labels and set their text styles, is there a way to use a custom font AND text styles from within interface builder? Or maybe somehow override their font-family while respecting the text style already set on them?
No, you'd need to use the programmatic approach. However, it is easy to write a little loop that runs through all your labels and for each one, fetches the dynamic type "role" already set in interface builder and substitutes a UIFontMetrics value based on that "role" and the desired custom font.

GWT Read-only TextArea will not resize

GWT newbie here. I have found that when I make a TextArea read-only useful features such as dynamic expansion and even word-wrapping stops working. My intention was to move a string from one text area, append it some way to some more strings, and then add this string into my read-only TextArea. I have doing something like this:
// Temporarily enable the field to set the value of the TextArea
logTextArea.setEnabled(true);
String remarks = // my string to add into the box
if (remarks.length() > 0) {
logTextArea.setEnabled.setValue(remarks);
}
// set read-only again
logTextArea.setEnabled.setEnabled(false);
I also have to work out how many lines I now span and explicitly set the height of the box (via setVisibleLines()). I have now found that it does not word-wrap, so I've had to add some more horrible bodge-code to further split up this string.
So I'm writing code to emulate functionality that comes for free on a normal writable TextArea. Has anyone else found this issue after setting a text-field read-only? Is there another widget I could possibly use to display a list of read-only strings that will auto resize and auto wrap for me?
Many thanks for your time,
tom
Text Area is fine for re-sizing and auto word wrap, even you have your text
area as read only.
Tested now by creating a test project for gwt and it is working fine.
Also Word Wrap is the default behavior of Text area if you want to turn it off then you need to explicitly do this "getElement().setAttribute("wrap","off");

Text not fitting into form fields (iTextSharp)

I created a .PDF file using Adobe Acrobat Pro. The file has several text fields. Using iTextSharp, I'm able to populate all the fields and mail out the .PDF.
One thing is bugging me - some of the next will not "fit" in the textbox. In Adobe, if I type more that the allocated height, the scroll bar kicks in - this happens when font size is NOT set to auto and multi-line is allowed.
However, when I attempt to set the following properties:
//qSize is float and set to 15;
//auto size of font is not being set here.
pdfFormFields.SetFieldProperty("notification_desc", "textsize", qSize, null);
// set multiline
pdfFormFields.SetFieldProperty("notification_desc", "setfflags", PdfFormField.FF_MULTILINE, null);
//fill the field
pdfFormFields.SetField("notification_desc", complaintinfo.OWNER_DESC);
However upon compilation and after stamping, the scroll bar does not appear in the final .PDF.
I'm not sure if this is the right thing to do. I'm thinking that perhaps I should create a table and flood it with the the text but the documentation makes little or no reference to scroll bars....
When you flatten a document, you remove all interactivity. Expecting working scroll bars on a flattened form, is similar to expecting working scroll bars on printed paper. That's why you don't get a lot of response to your question: it's kind of absurd.
When you fill out a rectangle with text, all text that doesn't fit will be omitted. That's why some people set the font size to 0. In this case, the font size will be adapted to make the text fit. I don't know if that's an option for you as you clearly state that the font size must be 15 pt.
If you can't change the font size, you shouldn't expect the AcroForm form field to adapt itself to the content. ISO-32000-1 is clear about that: the coordinates of a text field are fixed.
Your only alternative is to take control over how iText should fill the field. I made an example showing how to do this in the context of my book: MovieAds.java/MovieAds.cs. In this example, I ask the field for its coordinates:
AcroFields.FieldPosition f = form.GetFieldPositions(TEXT)[0];
This object gives you the page number f.page and a Rectangle f.position. You can use these variables in combination with ColumnText to add the content exactly the way you want to (and to check if all content has been added).
I hope you understand that:
it's only normal that there are no scroll bars on a flattened form,
the standard way of filling out fields clips content that doesn't fit,
you need to do more programming if you want a custom result.
For more info: please consult "iText in Action - Second Edition".

How can I set a custom size for the RichTextArea.Formatter.setFontSize() in GWT?

Using the RichTextArea in GWT, It looks like I can only change the font size to one of the values: LARGE, MEDIUM, SMALL, etc (RichTextArea.FontSize), but I want to be able to setFontSize of the RichTextArea.Formatter to a specific size in pt or in px.
How can I achieve that?
I've been digging a bit on this, and it would seem that it is unfortunately not possible, because browsers are limited in their handling of font sizes in the rich text editors. In particular, Firefox generates the (deprecated) <font size="x"></font> element when the font size is changed, and the value of x can be only in the 1-7 range.
If you have a look at the setFontSize method in RichTextAreaImplStandard (GWT source code), you'll see that it ends up calling the execCommand javascript function, which in the case of FontSize only accepts values in 1-7:
http://msdn.microsoft.com/en-us/library/ms536991%28VS.85%29.aspx
You can actually achieve that using string manipulation of the HTML code.
So if you are not using the background color property of the RichTextArea then what you have to do is to replace the "background-color=RED" to "font-size=12px". And then set it back to the RichTextArea object as setHTML().
This works fine as I've implemented this functionality in one of our production application..
Thanks,
Pratik.

VB6 Changing colors for every control on a form

I am trying to change the colour theme of an old VB6 application (make it look a bit more modern!).
Can someone tell me how I could change the backcolor of every control on a form without doing it for each and every control (label, button, frame etc!).
I have about 50 forms, all containing such controls and doing this manually for each form in code would take an age!
I am also open to better suggestions and ideas on how I can skin / theme a VB6 application?
Thanks in advance
The .frm files are simply standard ANSI text files. A background color property of a control would look like this:-
BackColor = &H80000005&
(Note the above is a system color but you can specify the RGB color using by using the lower 3 bytes and leaving the high byte 0).
A control such a Label would look like this:-
Begin VB.Label Label1
Caption = "Hello:"
Height = 285
Left = 90
TabIndex = 3
Top = 480
Width = 1305
End
So that task could be done lexically by parsing the .frm files and inserting (or replacing) the BackColor attribute line.
Edit:
Useful link posted in comments by MarkJ : Form Description Properties
You can do a for each and eliminate the controls you don't want.
Dim frmThing as Form
Dim ctlThing as Control
For Each frmThing In Forms
frmThing.BackColor = vbYellow
For Each ctlThing In frmThing.Controls
If (TypeOf ctlThing Is TextBox) Or _
(TypeOf ctlThing Is CheckBox) Or _
(TypeOf ctlThing Is ComboBox) Then
ctlThing.BackColor = vbYellow
End If
Next
Next
you could do this at runtime by looping the Controls collection and setting the background of each. This would give you the flexibility of changing your theme.
You could also work through the source files, parse out the controls and enter/change the background colours that you want. This approach is probably more work, for less reward.
Just for completeness...
ssCheck does not have a BackColor property and will produce an error using the aforementioned methods
~Mike~
It's going back quite a few years now, but wasnt there a 'Transparent' background color?
Set all the labels to have a transparent background, and you only need to set the form color once.