Fontawesome replacement font not displaying

I'm going insane trying to get this to work so I'm wondering if anyone has an idea how to accomplish this.

My current little project is a reskin of Joplin to have a go at some Joplin related CSS and getting it published as a plugin theme.
So far it has all gone pretty well, things are looking good (even if the process has been somewhat complicated in many places) however I've got to a point where I'm totally stuck.

The plan is to replace the current fontawesome icons with a new set and no matter what I've tried I just can't get them to display. The dev tools show that it sees my CSS changes to include the font family and the content but it always just comes up blank.

So as an example this is what I have in my chrome.css file taken from the CSS of a webfont I've downloaded (yes I know I don't need the fix for ie but I've just copied verbatim, trimming it down doesn't help either):

@font-face {
  font-family: 'replacement-font';
  src: url('./webfont/replacement-font.eot?16747377');
  src: url('./webfont/replacement-font.eot?16747377#iefix') format('embedded-opentype'),
       url('./webfont/replacement-font.woff2?16747377') format('woff2'),
       url('./webfont/replacement-font.woff?16747377') format('woff'),
       url('./webfont/replacement-font.ttf?16747377') format('truetype'),
       url('./webfont/replacement-font.svg?16747377#replacement-font') format('svg');
  font-weight: normal;
  font-style: normal;
}

My plugin src structure looks like the following:

├── src
│   ├── chrome.css
│   ├── chrome.css.map
│   ├── index.ts
│   ├── manifest.json
│   ├── note.css
│   └── webfont
│       ├── replacement-font.eot
│       ├── replacement-font.svg
│       ├── replacement-font.ttf
│       ├── replacement-font.woff
│       └── replacement-font.woff2

And I'm trying to invoke it using the following CSS:

.fa-plus:before {
  font-family: "replacement-font" !important;
  content: "\e833" !important;
}

The dev tools imply that it might have worked when inspecting that element:

image

but alas nothing shows up.

I've tested the font on a plain html file using exactly the same CSS and it works fine. I'm clearly missing something important here...

You're assuming that the path in your .css is relative to the plugin root:

  src: url('./webfont/replacement-font.eot?16747377');
  src: url('./webfont/replacement-font.eot?16747377#iefix') format('embedded-opentype'),
       url('./webfont/replacement-font.woff2?16747377') format('woff2'),
       url('./webfont/replacement-font.woff?16747377') format('woff'),
       url('./webfont/replacement-font.ttf?16747377') format('truetype'),
       url('./webfont/replacement-font.svg?16747377#replacement-font') format('svg');

I'm pretty sure this isn't the case. Also I think it may even be different when you're running dev version of the plugin compared to installing a jpl, though I'm not 100% sure on this one.

1 Like

That makes sense, I figured I'd need to work something that when I came to the packaged .jpl version but I'm still doing it as a dev plugin so I can rapidly make proof of concept changes before going full ham on it. I had assumed the dev version was essentially just running out of the folder specified so the path would have been OK.

I'm assuming I need to do something with joplin.plugins.installationdir to get that path and make it relative to that instead.

I'm not sure actually. If the css is applied from the main process rather than from a plugin then the current dir will be something else.
Even inside a plugin the working dir isn't the installationDir (or at least wasn't last time I checked) because Joplin copies the main plugin index.js file to the temp dir inside the profile and executes it from there, while other non-code assets remain in the installation dir.

Ok so it does work if you pass the full installationdir to it.

e.g. by default mine was /home/me/myplugin/dist/ so placing the full path (/home/me/myplugin/dist/webfont/replacement-font.eot into my src: lines seems to work perfectly and shows the icons.

Next I just need to work out how to pass the result of await joplin.plugins.installationDir(); into my CSS file...