How can I use custom web fonts in django cms icons - python-3.x

My question is how does the /admin/djangocms_icon/includes/assets.html file look like? Can someone give a sample supposing I am using font awesome 5? Below are the configuration settings that I followed on Github.
Configuration
This addon provides a default template for all instances. You can provide
additional template choices by adding a DJANGOCMS_ICON_TEMPLATES
setting::
DJANGOCMS_ICON_TEMPLATES = [
('svg', 'SVG template'),
]
Web Font Icons
##############
The django CMS Icon plugin ships with Font Awesome 4 as default. This can
be changed by overriding the following setting::
DJANGOCMS_ICON_SETS = [
('fontawesome4', 'fa', 'Font Awesome 4'),
]
To use Font Awesome 5 in the above example; see the options below from the DJANGOCMS_ICON_SETSlisted.
In addition you need to load the resources for your fonts in /admin/djangocms_icon/includes/assets.html. Add this file to your project
in order for the icon picker to pick up your custom icons in the admin.
The icon picker supports numerous font libraries <http://victor-valencia.github.io/bootstrap-iconpicker/>
out of the box. You can also add multiple font sets like this::
DJANGOCMS_ICON_SETS = [
('elusiveicon', 'el', 'Elusive Icons'),
('flagicon', 'flag-icon', 'Flag Icons'),
('fontawesome4', 'fa', 'Font Awesome 4'),
('fontawesome5regular', 'far', 'Font Awesome 5 Regular'),
('fontawesome5solid', 'fas', 'Font Awesome 5 Solid'),
('fontawesome5brands', 'fab', 'Font Awesome 5 Brands'),
('fontawesome5light', 'fal', 'Font Awesome 5 Light',
'5.3.1_pro'),
('glyphicon', 'glyphicon', 'Glyphicons'),
('ionicon', 'ion', 'Ionicons Icons'),
('mapicon', 'map-icon', 'Map Icons'),
('materialdesign', 'zmdi', 'Material Design'),
('octicon', 'octicon', 'Octicons'),
('typicon', 'typcn', 'Typicons'),
('weathericon', 'wi', 'Weather Icons'),
]

I just had to figure this out myself. It depends on whether you're trying to include a preconfigured font or your own.
Including preconfigured fonts
There is an example of an assets.html provided in the official repository at djangocms_icon/templates/admin/djangocms_icon/includes/assets.html and it's in fact linking to Font Awesome 5 (5.3.1 specifically):
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
In order to include another font:
Copy the assets.html file into your templates folder at templates/admin/djangocms_icon/includes/assets.html (it overrides the template's default),
Add another <link> referring to your (external or local) font(s) of choice,
Add the references in your settings.py's DJANGOCMS_ICON_SETS by copying the respective element(s) from the docs.
Including custom fonts
For custom fonts, it's a tad more complicated. In my case, I only had a single .ttf file with custom icons, no CSS. In this case, the assets.html looks like this:
{% load static %}
<link rel="stylesheet" href="{% static 'css/icons/my_icons.css' %}">
In my_icons.css, include the font with an #font-face-rule and add a general myicon class plus individual classes for each of the icons:
#font-face {
font-family: "My Icons";
font-weight: normal;
font-style: normal;
src: url("../../fonts/MyIcons.ttf") format("truetype");
}
.myicon {
font-family:"My Icons";
font-style: normal;
font-size: inherit;
}
.myicon-A:before {
content:"A";
}
.myicon-B:before {
content:"B";
}
.myicon-C:before {
content:"C";
}
...
Next, put a JSON file at static/js/my_icons.js (or wherever you want) with a list of all the icon classes:
{
"iconClass": "myicon",
"icons": ["myicon-A",
"myicon-B",
"myicon-C",
"myicon-D",
...
]
}
(To generate all possible symbols, I opened the font in MacOS's font manager, copied all of the glyphs with cmd-A/cmd-C - they are really just letters - and used that to generate the rules with a short Python script.)
Finally, in your settings.py, you load the JSON and set up the reference to your custom font:
with open('path/to/static/js/my_icons.js')) as iconfile:
MY_ICON_SET = iconfile.read()
DJANGOCMS_ICON_SETS = [
(MY_ICON_SET, # = the content of the JSON file
'myicon', # = the css class
'My Icons' # = the label in the admin interface
),
]
That should be it. Don't forget to include your custom font in your website as well (e.g. in the header of your base.html template) for the icons to show up in the content as well.

Related

Making Sencha architect aware of an xtype

I am using Architect 4.3.2.19, CMD 7.6.0.87 Modern framework.
I have a couple of xtypes for things like Ext.Panel - example:
Ext.define('Ext.PanelSection', {
extend: 'Ext.Panel',
xtype: 'panelsection',
alias: 'widget.panelsection',
config: {
shadow: true,
ui: 'panel-section-title',
layout: 'vbox',
header: {
height: 18,
minHeight: 18,
maxHeight: 18,
style: 'text-decoration:underline'
}
}
});
The source for the xtype is held in a common.js file that is in the resource section of the Architect project inspector.
So in the architect I add an Ext.Panel to the canvas and then I then add a process config
config.xtype = 'panelsection';
return config;
It works beautifully but the architect will still show the panel header full height which makes laying out the panel a bit tricky. Is there a way of creating an xtype so that the architect is aware of it's config.
There was something I just now thought about in reading your question. It could be the Theme's .css is overriding your settings, possibly.
Two things you can try:
Once you place your PanelSection you could go down the Theme Config panel and change the default height to 18px.
You could you add another resource file containing .css, I did this, and allow it to override the panel header height. I did it for my Tabs in a TabPanel, it worked like a charm. But you'd need to find out what css class to override. In searching the .arch-internal-preview.css file, I found references to:
x-panel.x-header-position-top > .x-max-height-el {
flex-direction: column
}
You could try to add a height variable of 18px under the flex-direction and see if that changes the height of the header.
Anyway below is what I've done to change my Tabs in a separate resouce file.
Ex:
.x-tabpanel {
font-size: 28px;
}
.x-tab{
width: 250px;
}

Custom font is not loaded in stripe element

I am specifing custom font for stripe element according to documentation. But stripe input font is differs with other input(same custom font).
I have created simple page with two inputs. First is html <input>, second is stripe elements input. I am specifing custom font for html input and for stripe input. But stripe input font is different(stripe input is second):
Here is js code to create stripe element:
var elements = stripe.elements({
fonts: [
{
cssSrc: 'http://db.onlinewebfonts.com/c/0abeb2471faeb5269db428b9eac2075e?family=GT+Walsheim+Pro+Regular',
},
],
});
var elementStyles = {
base: {
fontFamily: 'GT Walsheim Pro Regular',
fontSize: '25px',
},
};
var cardNumber = elements.create('cardNumber', {
style: elementStyles,
});
cardNumber.mount('#example-card-number');
Full reproduce code is available at github repo. Do you have any ideas why input font looks different?
Custom fonts in Stripe have to be loaded over HTTPS. Neither the font-face definition file nor the underlying custom font files are being served securely:
http://db.onlinewebfonts.com/c/0abeb2471faeb5269db428b9eac2075e?family=GT+Walsheim+Pro+Regular
#font-face {font-family: "GT Walsheim Pro Regular";
src: url("http://db.onlinewebfonts.com/t/0abeb2471faeb5269db428b9eac2075e.eot"); /* IE9*/
src: url("http://db.onlinewebfonts.com/t/0abeb2471faeb5269db428b9eac2075e.eot?#iefix") format("embedded-opentype"), /* IE6-IE8 */
url("http://db.onlinewebfonts.com/t/0abeb2471faeb5269db428b9eac2075e.woff2") format("woff2"), /* chrome firefox */
url("http://db.onlinewebfonts.com/t/0abeb2471faeb5269db428b9eac2075e.woff") format("woff"), /* chrome firefox */
url("http://db.onlinewebfonts.com/t/0abeb2471faeb5269db428b9eac2075e.ttf") format("truetype"), /* chrome firefox opera Safari, Android, iOS 4.2+*/
url("http://db.onlinewebfonts.com/t/0abeb2471faeb5269db428b9eac2075e.svg#GT Walsheim Pro Regular") format("svg"); /* iOS 4.1- */
}
The fix is to serve both the font-face file and an underlying font resources using HTTPs. As a quick example to see it working you can take one of the woff files and provide it to Stripe as follows:
var elements = stripe.elements({
fonts: [
{
family: "GT Walsheim Pro Regular",
src:
"url(https://db.onlinewebfonts.com/t/0abeb2471faeb5269db428b9eac2075e.woff)",
weight: "500",
},
],
});
Note that I updated the protocol from one of the resources to https://.
With this change, the fonts load correctly in the iframe as seen below:
Hope this helps!

chrome extension shadow DOM import boostrap fonts

so I'd like to display bootstrap 3 icons in a shadowroot added from a chrome extension content script. So far its not working, help?
manifest.js does include the woff file in web_accessible_resources
shadow root has style tag with:
#import url(chrome-extension://__MSG_##extension_id__/fonts/glyphicons-halflings-regular.woff2);
What am I missing?
To import a font, you should not use #import url which is used to import a CSS stylesheet.
Instead, you should use the #font-face directive.
Also, this directive should be placed in the <head> element of the HTML page, not inside the Shadow DOM.
host.attachShadow( { mode: 'open' } )
.innerHTML = `
<style>.icon { font-family: Icons; color: green ; font-size:30pt }</style>
<span class="icon">&#xe084</span>`
#font-face {
font-family: "Icons" ;
src: url("https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.7/fonts/glyphicons-halflings-regular.woff2") format("woff2")
}
<div id=host></div>
You can read this SO answer for further details.

Sublime 3 font size of definition hover

Is there a way to manage the font size of the function definition hover on ST3?
Here's what I see:
I've tried adding font.size to the theme for this element which is popup_control html_popup according to docs but it doesn't appear to accept this.
Update: I found that pasting this CSS in my color theme plist addresses the list/links but not the title. I have tried to use a plugin like ScopeHunter to find the context of the 'definitions' title but it doesn't work for popups.
<key>popupCss</key>
<string><![CDATA[
html {
background-color: #404238;
color: #F8F8F2;
}
a {
color: #66D9EF;
}
.error, .deleted {
color: #F92672;
}
.success, .inserted {
color: #A6E22E;
}
.warning, .modified {
color: #FD971F;
}
]]></string>
The best thing to do is look at the HTML that is used in the popup, to help decide what CSS selectors to use in the color scheme's popupCss to change the appearance of the popup.
In this case, the code is in Packages/Default/symbol.py, which you can view using https://packagecontrol.io/packages/PackageResourceViewer:
<body id=show-definitions>
<h1>Definition%s:</h1>
<p>
...
</p>
</body>
So you can use the following CSS in your popupCSS to target it and change the color of the "Definitions" text, for example - to prove the selector is working (the official recommendation is to use the id from the body tag):
#show-definitions h1 {
color: #b3bc20;
}
however, specifying the font-size seems to have no effect, at least in build 3154, so I think there is a bug in ST.

Possible to add SVG ::before element and have access to stroke and fill?

Is it possible to add a before element in CSS like this:
ul {
li:before {
content: url('../icons/fancy-symbol.svg');
}
}
and have access to the svg's objects (e.g. a specific line or rectangle) and properties (e.g. the stroke-width, strike and fill color)?
Or is there a workaround for these kind of situations?
The use case is to color some lines on hover and animate the svg on click.
You can specify a fragment on the SVG URL, like ../icons/fancy-symbol.svg#red, then have CSS inside the file react to that:
<style>
#red:target ~ .some-element-here {
fill: red;
}
</style>
This won't let you specify properties dynamically, but it can be useful for interaction states, especially with a preprocessor.
Alternatively, if the SVG file is small enough, you can use preprocessors to change properties in a Data URI, like with sass-svg, or manually:
.li:before {
content: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'
fill='#{$color}'%3E...");
}
(By the way, it might be easier to use ul { list-style-image: url(...) } instead of pseudo-elements.)

Resources