How to set custom fonts in JavaFX Scene Builder using CSS - css

I'm making a GUI in JavaFX Scene Builder and would like all text (Labels, Text Fields, Comboboxes) to use the same font. The problem is it's a custom font that likely won't be on every client's computer.
I've tried CSS:
#font-face {
font-family: DIN;
src: url(DIN.tff);
}
.text {
-fx-font-family: DIN;
-fx-font-style: bold;
}
Saved the above code to file Font.css and tried applying it to each GUI element through Scene Builder's JavaFX CSS fields, but it's not working.
Have I made a mistake in the CSS? Or is there a better way to go about this? I'd prefer not to have to load the font and set it for every element in the Java code itself if I don't have to.

Make sure to use Font.loadFont to actually load the font on application startup. Then you should be able to use the font from CSS. Be careful to use the font's name, not the font file's name. That's a common mistake.
I have used the following before to load and use a custom font:
Font.loadFont(getClass().getResourceAsStream("/resources/fonts/marck.ttf"), 14);
and:
-fx-font-family: "Marck Script";
FYI: the quotes are only needed if the name contains a space.

Related

JavaFX modify font using CSS without displacing text

I want to easily change my application's font using CSS.
This is what I do to change it:
.root{
-fx-font-family: "Courier New";
}
The font's are changed but all the elements are displaced (I guess it's because of the new font's size).
How can I keep the fonts with the same position and size when changing the font?
Even the textareas are narrower...
I attach two pictures with the difference.
Thanks in advance.

Angular Material custom theme on dialog, snackbar,...entryComponents

I am using Angular & Material v6 and I have a question about the application of a custom theme on entryComponents like dialog or snack bar.
Actually, I put the Roboto font on all component using the custom theme of material but it is not applied to my dialog or snack-bar.
You can find a stackblitz example here
As you can see, the Roboto font is correctly applied on my page but if you open the dialog, the Time New Roman is used instead...
I just:
fork the example of dialog from angular material website.
add a custom theme.scss (using Roboto) and include it in angular-cli.json
remove the global font-family in style.css
Any advises, explanations ?
Somewhere in your app you need to apply your typography to the application page body so that all components automatically inherit from it including the overlay component that holds the dialog. In the stackblitz demo, you commented that out to test your typography:
body {
/* font-family: Roboto, Arial, sans-serif; */
margin: 0;
}
So you either need to replace that in your theme file with something like:
body {
font-family: mat-font-family($custom-typography);
margin: 0;
}
Or (you can't do this when using stackblitz) use the Angular Material typography class in your main index.html page:
<body class="mat-typography">
...
</body>
Also, your typography configuration needs to define sizes and weight for all of the typography levels used by Angular Material. An easy way to simply modify the default configuration is using a SASS merge. For example:
$custom-typography: map-merge(
mat-typography-config(),
mat-typography-config(
$font-family: 'Roboto, sans-serif'
)
);
This takes your definitions and writes them over the default configuration, leaving anything you didn't re-define intact.
And you only need to call mat-core() alone as it will call angular-material-typography() which in turn calls mat-base-typography().

Angular app styling unicode characters

I've got a stackblitz Angular 5 app for implementing table sorting here - https://stackblitz.com/edit/angular-rxdzom. It's based on the code from http://www.carbonatethis.com/sort-table-columns-with-angular-and-typescript/. It uses an ./app/sortable-table/sortable-column.component.css with the contents:
.caret-up:before {
content: "\f0d8";
}
.caret-down:before {
content: "\f0d7";
}
and an ./app/sortable-table/sortable-column.component.html that contains two i tags that reference these with the class attribute. Instead of showing the caret-up and caret-down, it substitutes a rectangular box. If I replace caret-up and caret-down with the Font Awesome library, "fa fa-caret-up" and "fa fa-caret-down", it works properly. My environment at work doesn't use Font Awesome and it's not an option to add it, so I need to create the css content manually as I'm attempting above. Any help is appreciated!
I've tried researching this on my own, and clearly have something that looks like it should work, it just doesn't. I've used references like http://webdesignerwall.com/tutorials/how-to-add-icon-fonts-to-any-element-with-css that seem to indicate the css is valid, and I've tried using ".caret-up i::before" which also does not work. I'm clearly missing something or doing something wrong. I even tried adding
padding-right: 10px;
font-family: "FontAwesome";
before the content property but that didn't help either.
I assume the css shown above is in your styles property of your component? If so, the issue is that the backspace needs to be escaped in your string. Update them to the following and you should be good!
.caret-up:before {
content: "\\f0d8";
}
.caret-down:before {
content: "\\f0d7";
}
An alternative for adding icons is through material icons
You can find the icons here : https://material.io/icons/
Include the following link in your index.html
And in the css add the class 'material-icons' to your property.
For example-
keyboard_arrow_up
You can refer to different symbols name on the above material icons link provided.
Okay, so a part of this was me being in the dark about our environment. We had updated font awesome to Semantic UI, which uses a port of the font awesome fonts so I just had to use those fonts. To do it manually, I could use:
.caret-up:after {
padding-right: 10px;
font-family: Icons;
content: "\f0d8";
}
.caret-down:after {
padding-right: 10px;
font-family: Icons;
content: "\f0d7";
}
and to put the icons after the text, I just needed to move the "ng-content" tag above the "i" tags for asc/desc sort order. So, using the Semantic UI fonts, my sortable-column.component.html became:
<ng-content></ng-content>
<i class="caret up icon" *ngIf="sortDirection === 'asc'"></i>
<i class="caret down icon" *ngIf="sortDirection === 'desc'"></i>
And it worked great. I forked my Stackblitz app at https://stackblitz.com/edit/angular-nfwe6j to show how this was accomplished in my environment using the Semantic UI 2.3.1 of the font awesome fonts.

Change font of WordPress theme "Zerif Lite"

I'm having trouble changing the font on a website I built using the WordPress theme Zerif Lite.
The page itself is (REMOVED LINK) - I want to change the font in the "testimonial" section or as its displayed there: "Teenused".
That weird font in the bottom of every box (a.client-name)
I have tried so far:
Custom CSS plugin - it lets me only change the font size, when I set new font there, it won't change anything.
Changed the theme's CSS files, also no luck there.
Will appreciate any kind of help.
You can change the font by targeting the correct selector, which is: .feedback-box .client-info .client-name. The current font is called Homemade Apple and is declared in the main theme's CSS file (style.css) at line 2797:
.feedback-box .client-info .client-name {
font-family: 'Homemade Apple', serif;
color: #404040;
}
Simply change that to your desired font, for example:
.feedback-box .client-info .client-name {
font-family: 'Montserrat', sans-serif;
color: #404040;
}
Have you try to add an !important rule to your CSS. It's either that or verify the load order from your styles.
When it comes down to a CSS style, the reason it may not be aplying is because there is another more specific selector, try adding parent selector to your rules, or it could also be that the theme's rules are loading after your rules and replacing them.
One last thing to check, when dealing with fonts: make sure your browser have access to and knows the font. If it does not finds it, it will just replace it with another one, without any warning.

How to Replace or Remove HTML Editor styles in the Sharepoint 2010 Ribbon

I want to replace the HTML Editor styles in the HTML Style dropdown on the editor ribbon with styles of my own creation. According to this MSDN article http://msdn.microsoft.com/en-gb/library/ms551040.aspx as soon as I start putting classes that begin with the pattern ms-rteCustom-XXXX(XXXX being a custom name) into CSS that's loaded in the page, the existing styles should be replaced. I would expect this to leave only my styles in the drop-down, however I can see all of the original Sharepoint styles, and then my styles.
Am I missing something in the documentation, or is it lying to me? As far as I can tell, the original styles come from the corev4.css that's also loaded by the master page, however as my CSS is loaded later, it seems like any styles already in the drop down should be cleared.
Here is one of the new/custom styles in the CSS I'm using;
H3.ms-rteElement-H3CompanyName
{
-ms-name:"Heading 3";
}
.ms-rteElement-H3CompanyName
{
font-family: Arial, Helvetica, sans-serif;
font-size: small;
font-style: normal;
line-height: normal;
font-weight: bold;
font-variant: normal;
text-transform: none;
color: #000000;
}
The best way to remove the styles, assuming this is a publishing page, is to modify the control within your page layout.
<PublishingWebControls:RichHtmlField FieldName="PublishingPageContent" HasInitialFocus="True" MinimumEditHeight="400px" runat="server" PrefixStyleSheet="customPrefix"/>
By declaring a new PrefixStyleSheet it will remove all of the default styles so that you can only provide your own.
Rather than JavaScript, you can also use css to hide Markup Styles.
For example, this is how to hide Heading 1s.
#Ribbon\.EditingTools\.CPEditTab\.Paragraph\.ElementWithStyle\.Menu\.Styles #ElementWithStyle0-Menu,
#Ribbon\.EditingTools\.CPEditTab\.Paragraph\.ElementWithStyle\.Menu\.Styles #ElementWithStyle4-Menu
{display:none;}
I'm not sure where you've read that "as soon as custom styles are added, old ones are removed". The way I read the documentation, it correlates to my experience with this - that the custom styles are just added to the bottom of the dropdown list.
What you could do though, is to override the built-in ones with your custom style as well. Just use the exact same name as the OOTB styles and enter your own styles in the CSS file. Example: to override the style "Callout 1", add a rule for .ms-rteElement-Callout1 in your CSS and add your own styling there.
Another option is to write a JavaScript function and attach it to the ribbon resized event using
SP.UI.Workspace.add_resized(your_javascript_function_name);
Inside your function, you can use a jQuery statement to remove all (or the first X) elements from the dropdown list in the ribbon control.
It looks like the only way to remove elements from the Markup Style drop down list is to modify files in the main Sharepoint hive. A reset of IIS is probably a good idea after these changes, then ctrl-F5 to fully refresh what the browser is seeing.
This is not normally recommended as these files may change as part of a Sharepoint upgrade, however it seems to be the only way that reliably works.
To remove unwanted elements from the Markup Style dropdown, remove all CSS rules that affect classes named in this pattern .ms-rteElement-XXXX . Our own styles for use in this menu are added in one of our own style sheets.
There are four files that need to be modified, two copies of Controls.css and two copies of Corev4.css.
They are located as follows;
Controls.css
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES\PublishingLayouts\en-us\Controls.css
COREV4.CSS
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1033\STYLES\COREV4.CSS
CONTROLS.CSS
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1033\STYLES\CONTROLS.CSS
COREV4.CSS
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1033\STYLES\Themable\COREV4.CSS
I would add your CSS to the alternate CSS option under Look and Feel in your site settings. If you dont see the option, turn on publishing options.
Then add the CSS you want. It gets loaded last and to make sure, you can add !important to the styles.
Look here for more details... Half way down the page.
Sharepoint 2010 Themes and Alternate CSS for overriding Core
EDIT FOR COMMENT BELOW:
$('a#Ribbon.EditingTools.CPEditTab.Markup.ElementWithStyle-Large').click(function(){
$('a#ElementWithStyle3-Menu').parent().hide();
});
I finally got this to work using purely Javascript. What I did is register a PageComponent and then add a handler for the appropriate command (In the case of Markup Styles, the command is called 'ElementWithStyleOptionsOpen').
Here is the MSDN documentation about how to develop PageComponents: http://msdn.microsoft.com/en-us/library/ff407303.aspx#Y300
In my custom PageComponent class I registered 'ElementWithStyleOptionsOpen' as a GlobalCommand:
getGlobalCommands: function () {
return ['ElementWithStyleOptionsOpen'];
}
...And also added it to canHandleCommand:
canHandleCommand: function (commandId) {
if (commandId === 'ElementWithStyleOptionsOpen') {
return true;
}
else {
return false;
}
Finally my HandleCommand looks like this:
handleCommand: function (commandId, properties, sequence) {
if(commandId=='ElementWithStyleOptionsOpen') {
//Remove styles that have the word Colored
jQuery('li.ms-cui-menusection-items:contains("Colored")').remove();
}
}

Resources