Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using latest material design TTF font #87

Closed
thammoud opened this issue Sep 16, 2020 · 10 comments
Closed

Using latest material design TTF font #87

thammoud opened this issue Sep 16, 2020 · 10 comments

Comments

@thammoud
Copy link

Hello,

Thank you for the great product. We see fonts on the https://materialdesignicons.com/ website that we would like to use and have no equivalent enum. We use Java 8 with Swing so are stuck with the 2.6 release. We did the following:

  1. Download the zip file from the site. The zip includes a TTF file that we use.
  2. Implemented an AbstractIkonHandler with our own prefix, enum and proper service configuration.
  3. In the debugger, we can see the font being loaded and all appropriate code being called. IkonResolver creates the font. No errors.
  4. FontIcon#setProperties return a 0 width for a non-null code. this.width = g2.getFontMetrics().charWidth(ikon.getCode());
  5. paintIcon throws an exception complaining about the 0 width.

The only thing I suspect is the way the TTF is imported. Any pointers will be greatly appreciated. Again, thank you for a wonderful project.

Tarek

@aalmiray
Copy link
Collaborator

Is the font family set in your custom IkonResolver the appropriate one?
Are you using the official materialdesign icon pack at the same time as your custom icon pack?

@aalmiray aalmiray self-assigned this Sep 16, 2020
@thammoud
Copy link
Author

No. I left the family the same as Material Design and yes I am using the material design pack at the same time.

@aalmiray
Copy link
Collaborator

I'll perform another check. Based on https://github.com/Templarian/MaterialDesign-Font the font family in version 5.5.55 is set to "Material Design Icons".

@thammoud
Copy link
Author

and that is what I have.

public String getFontFamily() {
return "Material Design Icons";
}

I switched to the TTF in the https://github.com/Templarian/MaterialDesign-Font link.

public enum MaterialDesignExtras implements Ikon { MDI_SITE_MAP2("myprefix-mdi-sitemap" , '\uf4aa'), MDI_SITE_MAP("mdi-sitemap" , '\uf4aa'),

The site map2 throws the width exception. site map works fine.

@aalmiray
Copy link
Collaborator

Same icon code but different description yet one fails and the other succeeds? Now that's indeed weird. I wonder what else could cause this.

@thammoud
Copy link
Author

No idea why. I made sure to use the same code. BTW, I never see the AbstractIkonHandler#getFontFamily being called. The only thing I can think of is some conflict with the existing material design.

The exception for the record:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Width (0) and height (16) cannot be <= 0 at java.awt.image.DirectColorModel.createCompatibleWritableRaster(DirectColorModel.java:1016) at java.awt.image.BufferedImage.<init>(BufferedImage.java:333) at org.kordamp.ikonli.swing.FontIcon.paintIcon(FontIcon.java:73) at javax.swing.plaf.basic.BasicButtonUI.paintIcon(BasicButtonUI.java:292) at javax.swing.plaf.basic.BasicButtonUI.paint(BasicButtonUI.java:216) at javax.swing.plaf.metal.MetalButtonUI.update(MetalButtonUI.java:139) at javax.swing.JComponent.paintComponent(JComponent.java:780)

@aalmiray
Copy link
Collaborator

I see. Swing's IkonResolver relies on the getFontResourcePath() from your custom IkonHandler. That paths points to the TTF file found in the classpath.

@thammoud
Copy link
Author

thammoud commented Sep 16, 2020

So I removed the existing material design and it still fails. Then I replaced the TTF with the one from your distribution (2.6) and that worked. No code changes. The problem is I need the latest.

@aalmiray
Copy link
Collaborator

As far as I can tell the latest uses codepoints that are beyond a single char (2 bytes) which is the limit currently supported by Ikonli.

mdi-access-point in 1.7.22 is at f002
mdi-access-point in 5.5.55 is at f0003

@thammoud
Copy link
Author

Oh thank you. That's a lot of enums to rewrite to support the int limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants