flutter-packages icon indicating copy to clipboard operation
flutter-packages copied to clipboard

Allow obtaining the font files

Open DavBfr opened this issue 4 years ago • 15 comments

Request

I'm the developer of the library pdf. This library renders PDF files from dart code. It can load TTF fonts to draw text in the document.

As far as I can see, this google-fonts library does not expose the font files, URL, or bytes in any way.

I would need something to get the Uint8List font data for any available fonts without duplicating this library.

Usage

import 'dart:io';
import 'dart:typed_data';

import 'package:pdf/widgets.dart';

void main() async {
  final pdf = Document();

  // Load the file here.
  // A google_font API would be much appreciated to replace this line
  // like: final Uint8List fontData = await GoogleFonts.getFontData('Lato');
  final Uint8List fontData = await File('open-sans.ttf').readAsBytes();
  final ttf = Font.ttf(fontData.buffer.asByteData());

  pdf.addPage(
    Page(
      build: (context) {
        return Center(
          child: Text(
            'Hello World',
            style: TextStyle(
              font: ttf,
              fontSize: 40,
            ),
          ),
        );
      },
    ),
  );

  await File('output.pdf').writeAsBytes(pdf.save());
}

Platforms:

  • iOS, Android, macOS, Web

DavBfr avatar Apr 26 '20 19:04 DavBfr

++1

BraveEvidence avatar May 14 '20 11:05 BraveEvidence

That would be awesome!!!

JaqueiraDev avatar Jul 17 '20 18:07 JaqueiraDev

Any progress on this? would be great to have this feature.

ahuruConnect avatar Nov 27 '20 10:11 ahuruConnect

Much Needed Feature!

mukhtharcm avatar Feb 05 '21 04:02 mukhtharcm

bump

derrick56007 avatar Feb 07 '21 22:02 derrick56007

Absolutely Required

arpanpreneur avatar Feb 18 '21 05:02 arpanpreneur

I will love it

eaedev avatar Mar 21 '21 15:03 eaedev

This is a much required feature please

EducatedDeer avatar Mar 24 '21 21:03 EducatedDeer

any new news !!

Joseph-Nathan avatar May 10 '21 03:05 Joseph-Nathan

anu update ?

ganeshchenniah avatar May 10 '21 10:05 ganeshchenniah

I am also using Google Fonts, I first download it and using like this

theme: pw.ThemeData.withFont(
        base:
            Font.ttf(await rootBundle.load("assets/fonts/Sarabun-Regular.ttf")),
        bold: Font.ttf(await rootBundle.load("assets/fonts/Sarabun-Bold.ttf")),
      ),

GuvanchBayryyyev avatar May 12 '21 06:05 GuvanchBayryyyev

@GuvanchBayryyyev can you please elaborate?

salvadorbarb1 avatar Jun 12 '21 20:06 salvadorbarb1

This is proving more complex than initially thought and requires a thorough refactor, along with tackling https://github.com/material-foundation/flutter-packages/issues/129.

guidezpl avatar Jun 19 '23 14:06 guidezpl