react-native-canvas icon indicating copy to clipboard operation
react-native-canvas copied to clipboard

Custom font API

Open Tanatcu opened this issue 6 years ago • 22 comments

Added simple custom font loader for using custom fonts inside canvas WebView

Tanatcu avatar Feb 19 '19 22:02 Tanatcu

Awesome work! To make it more compatible with the Web API: I think the canvas should have fonts property which will be a FontFaceSet. FontFaceSet will be initiated with a canvas instance and have add() and load() methods

iddan avatar Feb 20 '19 15:02 iddan

Thanks! About your idea. Do you mean that an access to the fontFaceSet will be possible via canvas.fonts property? And methods will be available like: canvas.fonts.add or canvas.fonts.load? Oh I see. It should be awesome and will give the opportunity to use FontFaceSet as original Web API class. But what your imagination about using FontFace class? As I saw in MDN and articles FontFace uses for preparing font to loading. I will check that can I use FontFaceSet only for loading, but it will be a bit later.

Tanatcu avatar Feb 20 '19 15:02 Tanatcu

Sweet! Thank you so much. FontFace can either get Canvas instance as well

iddan avatar Feb 20 '19 16:02 iddan

Hi @iddan. I'm sorry cause I have a lot of work on my job and finally I finished pull request. Could you check and note what I should fix?

Tanatcu avatar Apr 18 '19 16:04 Tanatcu

Also I have made new realization of toArg method. Could you check it?

Tanatcu avatar Apr 18 '19 16:04 Tanatcu

Looks good. But it doesn't use the FontFaceSet. Can you do it?

iddan avatar Apr 21 '19 09:04 iddan

As I understand logic of FontFaceSet usage in css, initialized class FontFaceSet saves in document.fonts property. And I save this property in this.fontFaceSet for more comfortable usage. What do you mean when tell "it doesn't use the FontFaceSet"?

Tanatcu avatar Apr 22 '19 07:04 Tanatcu

Sorry, I was not clear enough. I meant you should represent the fonts interface on the React Native Side with a class of FontFaceSet and expose an API is similar as possible to the web one

iddan avatar Apr 22 '19 10:04 iddan

I guess I understand what you've said) Are you telling about separated class FontFaceSet such as ImageData either Image either Path2D?

Tanatcu avatar Jul 16 '19 15:07 Tanatcu

Yes

iddan avatar Jul 18 '19 08:07 iddan

@jvink but this PR isn't finished yet

Tanatcu avatar Nov 28 '19 10:11 Tanatcu

@jvink this week or next i'll finish this PR. Currently i've found this changes doesn't work on iOS. it's important bug

Tanatcu avatar Nov 28 '19 10:11 Tanatcu

Hi! Any updates?

hvlong avatar Nov 05 '20 07:11 hvlong

Hey @Tanatcu any update? Very interested in this feature. Wondering what bug you found on iOS and if you were able to fix.

tebatalla avatar Mar 25 '21 21:03 tebatalla

Hey Guys, I need to use custom fonts @Tanatcu @tebatalla @hvlong do you have any updates or workarounds?

LautaroNavarro avatar Sep 29 '22 14:09 LautaroNavarro

Guys, if you need a workaround to render custom fonts you can just add @font-face { font-family: 'YourFontName'; src: url('FontURL.ttf'); } to the index.html file

LautaroNavarro avatar Sep 30 '22 01:09 LautaroNavarro

@LautaroNavarro Good point. Actually it's the same job as font loader does. But thank you for pinging, I'm going to refresh my memory and look, how this long-life PR could be finally finished.

Tanatcu avatar Sep 30 '22 07:09 Tanatcu

I made a workaround like that here after importing fonts for both android and ios, you can use them in canvas.

local('Alloy Ink') -> for ios
url('file:///android_asset/fonts/Alloy Ink.otf') -> for android

tolunaykan avatar Mar 14 '23 17:03 tolunaykan

@tolunaykan how did you import your fonts? I went the react-native-asset route, but can't seem to get them to load

laurenwilliams avatar Mar 20 '23 14:03 laurenwilliams

@tolunaykan could you explain what you did?

I tried adding my font to my node_modules/react-native-canvas/dist/index.html file like this...

<style>
  @font-face { font-family: 'Work Sans'; font-weight: 500; src: local('WorkSans-Medium'), url('WorkSans-Medium.ttf') format('truetype'); }
   ...
</style>

...but it didn't work.

@laurenwilliams did you figure out how to get this working?

rob-johansen avatar Jul 14 '23 01:07 rob-johansen

Hi @Tanatcu ! Would love this feature, any chance you're going to work on this PR more?

lexi-stein avatar Sep 14 '23 16:09 lexi-stein

@lexi-stein Tbh I would like to continue working on this PR but have quite big problems with free time. I will try to look to it but can't promise anything.

Tanatcu avatar Sep 25 '23 18:09 Tanatcu