brendan-duncan / image

Dart Image Library for opening, manipulating, and saving various different image file formats.
MIT License
1.17k stars 266 forks source link

Cant use ttf font #342

Closed nikhilvashisht closed 3 years ago

nikhilvashisht commented 3 years ago

I am trying to use my own font in drawString function. I tried to follow the instructions :--

/// If you want use own fonts following with this steps: /// 1. Get your .ttf file - important is to select file with specific style which you want /// for example when you download .ttf file from google fonts: select file from /static folder /// example name: Roboto-Black.ttf /// 2. Convert ttf file to fnt zip with page: https://ttf2fnt.com/ /// 3. Create dart file with code: /// void main() { /// String fileName = 'YourFontName-Style.zip'; /// // your file has to be in the same folder as this program /// File file = File('$fileName'); /// List bytes = file.readAsBytesSync(); /// print(bytes); /// } /// 4. Change fileName in code above to your file name /// 5. Run this program /// 6. Copy results /// 7. Create dart file in your project with code: /// final BitmapFont fontNameSizeStyle = BitmapFont.fromZip(_FONTNAME_SIZE_STYLE); /// const List _FONTNAME_SIZE_STYLE =

I have created a dart file and put the main function inside a class. This dart file and the .zip file are in the lib folder. I am trying to run this function by calling it by a button click, but I get 'No such file or directory' error. Can someone explain exactly how we have to run this program?

`class bitmap { void main() { String fileName = 'Playfair_Display.zip'; // your file has to be in the same folder as this program File file = File('$fileName'); List bytes = file.readAsBytesSync(); print(bytes); } }'

brendan-duncan commented 3 years ago

This would be a command-line dart program. You're just converting the .zip file to an Dart array of bytes so you can embed the zip file. If you're running from pressing a button, that means you're not in a command-line environment. You want to change fileName to wherever the file exists to be read from your environment. If you have another way of making the zip file contents available to BitmapFont, then you wouldn't need to do this.

nikhilvashisht commented 3 years ago

I was able to do this through command prompt. Thankyou!