Hi Team ,
I was trying to add font-awesome font icons as per tutorials
3.5.10.2. Using Icons from Other Font Libraries
below is my full code implemented to add font-awesome icons to my project
icon-awesome-style.scss
@mixin icon-awesome-style {
/* use !important to prevent issues with browser extensions that change fonts */
font-family: 'Font Awesome 5 Brands' !important;
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
/* Better Font Rendering =========== */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
@font-face {
font-family: 'Font Awesome 5 Brands';
font-style: normal;
font-weight: 400;
font-display: block;
src: url("../../fonts/fontawesome/webfonts/fa-brands-400.eot");
src: url("../../fonts/fontawesome/webfonts/fa-brands-400.eot?#iefix") format("embedded-opentype"), url("../../fonts/fontawesome/webfonts/fa-brands-400.woff2") format("woff2"), url("../../fonts/fontawesome/webfonts/fa-brands-400.woff") format("woff"), url("../../fonts/fontawesome/webfonts/fa-brands-400.ttf") format("truetype"), url("../../fonts/fontawesome/webfonts/fa-brands-400.svg#fontawesome") format("svg"); }
.fab {
font-family: 'Font Awesome 5 Brands';
font-weight: 400; }
@font-face {
font-family: 'Font Awesome 5 Free';
font-style: normal;
font-weight: 400;
font-display: block;
src: url("../../fonts/fontawesome/webfonts/fa-regular-400.eot");
src: url("../../fonts/fontawesome/webfonts/fa-regular-400.eot?#iefix") format("embedded-opentype"), url("../../fonts/fontawesome/webfonts/fa-regular-400.woff2") format("woff2"), url("../../fonts/fontawesome/webfonts/fa-regular-400.woff") format("woff"), url("../../fonts/fontawesome/webfonts/fa-regular-400.ttf") format("truetype"), url("../../fonts/fontawesome/webfonts/fa-regular-400.svg#fontawesome") format("svg"); }
.far {
font-family: 'Font Awesome 5 Free';
font-weight: 400; }
@font-face {
font-family: 'Font Awesome 5 Free';
font-style: normal;
font-weight: 900;
font-display: block;
src: url("../../fonts/fontawesome/webfonts/fa-solid-900.eot");
src: url("../../fonts/fontawesome/webfonts/fa-solid-900.eot?#iefix") format("embedded-opentype"), url("../../fonts/fontawesome/webfonts/fa-solid-900.woff2") format("woff2"), url("../../fonts/fontawesome/webfonts/fa-solid-900.woff") format("woff"), url("../../fonts/fontawesome/webfonts/fa-solid-900.ttf") format("truetype"), url("../../fonts/fontawesome/webfonts/fa-solid-900.svg#fontawesome") format("svg"); }
.fa,
.fas {
font-family: 'Font Awesome 5 Free';
font-weight: 900; }
.IcoAwesome {
@include icon-awesome-style;
}
IconAwesome
import com.vaadin.server.FontIcon;
import com.vaadin.server.GenericFontIcon;
public enum IconAwesome implements FontIcon {
HEADPHONES(0XE900),
SPINNER(0XE905);
public static final String FONT_FAMILY = "IconAwesome";
private int codepoint;
IconAwesome(int codepoint) {
this.codepoint = codepoint;
}
@Override
public String getFontFamily() {
return FONT_FAMILY;
}
@Override
public int getCodepoint() {
return codepoint;
}
@Override
public String getHtml() {
return GenericFontIcon.getHtml(FONT_FAMILY, codepoint);
}
@Override
public String getMIMEType() {
throw new UnsupportedOperationException(FontIcon.class.getSimpleName()
+ " should not be used where a MIME type is needed.");
}
public static IconAwesome fromCodepoint(final int codepoint) {
for (IconAwesome f : values()) {
if (f.getCodepoint() == codepoint) {
return f;
}
}
throw new IllegalArgumentException("Codepoint " + codepoint
+ " not found in IconAwesome");
}
}
IcoAwesomeIcon
import com.haulmont.cuba.gui.icons.Icons;
public enum IcoAwesomeIcon implements Icons.Icon {
HEADPHONES("ico-awesome:HEADPHONES"),
SPINNER("ico-awesome:SPINNER");
protected String source;
protected String name;
IcoAwesomeIcon(String source) {
this.source = source;
}
IcoAwesomeIcon(String source,String name) {
this.source = source;
this.name = name;
}
@Override
public String source() {
return source;
}
@Override
public String iconName() {
return name;
}
}
IcoAwesomeIconProvider
import com.haulmont.cuba.web.gui.icons.IconProvider;
import com.vaadin.server.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
@Order(10)
@Component
public class IcoAwesomeIconProvider implements IconProvider {
private final Logger log = LoggerFactory.getLogger(IcoAwesomeIconProvider.class);
@Override
public Resource getIconResource(String iconPath) {
Resource resource = null;
iconPath = iconPath.split(":")[1];
try {
resource = ((Resource) IconAwesome.class
.getDeclaredField(iconPath)
.get(null));
} catch (IllegalAccessException | NoSuchFieldException e) {
log.warn("There is no icon with name {} in the FontAwesome icon set", iconPath);
}
return resource;
}
@Override
public boolean canProvide(String iconPath) {
return iconPath.startsWith("ico-awesome:");
}
}
web-app
cuba.iconsConfig = +com.vtss.vtower.web.screens.utils.fonts.IcoAwesomeIcon
helium-ext
@import "app/icon-awesome-style";
Questions
From what is the value
0XE900
which is used inHEADPHONES(0XE900)
refers to ? For exampe for iconarrows-alt
what shall i put ?
Also About the valuesource
how can i refere to it
ARROWS_ALT("icon-awesome:arrows-alt"),
this is what i’m trying to put
I i’m checking w3schools fontawesome5 icons reference but actually i don’t know from where can get this values
Is their is any thing is wrong with my implementation , if any please guide me