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

Multiple spaces in PDF being squashed to single space in iOS during SVG conversion #8935

Closed
SnailCoil opened this issue Sep 19, 2017 · 5 comments

Comments

@SnailCoil
Copy link

SnailCoil commented Sep 19, 2017

Link to PDF file (or attach file here):
double_spaces.pdf

Configuration:

  • Web browser and its version: AppleWebKit/603.3.8 Version/10.0 Mobile/14G60 Safari/602.1
  • Operating system and its version: iOS 10.3.3
  • PDF.js version: [email protected]
  • Is an extension: I'm not sure the answer to this. I'm using a small wrapper library in my web app that's specifically for Angular 2+, https://github.com/VadimDez/ng2-pdf-viewer

Steps to reproduce the problem:

  1. Convert the attached PDF, or any PDF that contains multiple spaces in a row, to SVG
  2. Observe multiple spaces being squashed to a single space

What is the expected behavior? (add screenshot)
chrome_desktop_spaces
Here is the PDF generated on desktop. The double spaces in the PDF are mirrored here.

What went wrong? (add screenshot)
safari_ios_spaces

iOS is automatically squashing multiple spaces to a single space. I verified that the SVG converter generated the correct glyphs, but when the correct string ("double  spaces  double  spaces") was assigned to the svg element's text content, the double spaces disappeared. The reason for this is logical: multiple spaces in HTML are considered to be no different than a single space.

However, desktop chrome conveniently ignores this, and renders multiple spaces with no problem. Is there a way that we can trick iOS into inserting the multiple spaces? I wondered if we could use non-breaking spaces in place of spaces to get the same functionality...

@yurydelendik
Copy link
Contributor

yurydelendik commented Sep 19, 2017

multiple spaces in HTML are considered to be no different than a single space.

SVG is an XML format. xml:space="preserve" shall preserve the spaces.

@SnailCoil
Copy link
Author

Perhaps it could be a symptom of https://bugs.webkit.org/show_bug.cgi?id=112032

@yurydelendik
Copy link
Contributor

Perhaps it could be a symptom of https://bugs.webkit.org/show_bug.cgi?id=112032

That is the exact issue you are documenting here. The bug above lists a workaround to add xml:space="preserve" to each tspan, but this will increase document size and memory usage.

@SnailCoil SnailCoil changed the title Multiple spaces in PDF being squashed to single space in iOS Multiple spaces in PDF being squashed to single space in iOS during SVG conversion Sep 21, 2017
@SnailCoil
Copy link
Author

I made a pull request that will prevent the spaces from collapsing, but the overhead is of course unnecessary unless using webkit

@Snuffleupagus
Copy link
Collaborator

I'm not sure if this issue is still relevant after PR #9340, even beside the fact that the SVG-backend isn't officially supported; please note https://github.com/mozilla/pdf.js/wiki/Frequently-Asked-Questions#backends

With PR #9340, which fixed a very large number of font bugs, we're now moving all glyphs to the Private Use Area (PUA) since that both fixes and prevents a large number of glyph mapping issues.
Hence, even with the SVG-backend you'd now need to use a separate textLayer (same as with the canvas-backend) in order for e.g. text-selection to work correctly. As such, this issue is likely no longer relevant and can be closed as WONTFIX.

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

No branches or pull requests

4 participants