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

glyphBounds and glyphAdvance return hard coded values #22

Closed
magnatronus opened this issue Nov 26, 2018 · 6 comments
Closed

glyphBounds and glyphAdvance return hard coded values #22

magnatronus opened this issue Nov 26, 2018 · 6 comments

Comments

@magnatronus
Copy link

I have been looking at allowing text wrap, and from your suggestion have been attempting to use stringBounds().

This issue I have is that the both glyphBounds() and glyphAdvance() return hard coded values, therefore it is impossible to accurately use stringBounds() to determine the length of a string.

  double glyphAdvance(int charCode) {
    return 0.454;
  }

  PDFRect glyphBounds(int charCode) {
    return const PDFRect(0.0, 0.0, 0.4, 1.0);
  }

for example:

String foo = "WW";
String bar = "ii";

stringBounds() says these are the same length, but they are not a W is wider that i.

Is there any other way of accurately determining the wide of a string, or is it that this is currently not possible?

@DavBfr
Copy link
Owner

DavBfr commented Nov 26, 2018

Yes, those functions are correctly implemented with ttf fonts.
Look at the file /pdf/test/ttf_test.dart for an example.

@magnatronus
Copy link
Author

Thanks for the pointer.

@magnatronus
Copy link
Author

magnatronus commented Nov 27, 2018

My first attempt at a document generator that has text that will wrap for both line and page can be found https://github.com/magnatronus/flutter-pdf-doc

thanks for the help so far!

@DavBfr
Copy link
Owner

DavBfr commented Dec 9, 2018

@magnatronus, I'm writing a Flutter-like Widget system wor this Pdf library. It is available in the widgets branch. If you want to help, that would be much appreciated!

It would look like this:

var pdf = Document();
pdf.addPage(Page(
  child: Column(children: <Widget>[
    Text("Hello World"),
    Image(image),
    Shape(shape),
  ])
));

@magnatronus
Copy link
Author

@DavBfr , if I can help sure, I will take a look.

@magnatronus
Copy link
Author

magnatronus commented Dec 12, 2018

@DavBfr I have been having a look at the widgets branch and have come across a few issues with the way it is currently set up.

You have defined your own classes called, for example, StatelessWidget, Widget, LimitedBox , Context, but as Flutter already has these defined when in a Flutter environment they clash with the Flutter classes. I know they could be name-spaced but as they are a fundamental part of the underlying Flutter building blocks I wondered whether they should be prefixed , maybe with Pdf to make they unique to your library?

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

No branches or pull requests

2 participants