auburnsounds / printed Goto Github PK
View Code? Open in Web Editor NEWGenerate PDF/SVG/HTML with D, with a Canvas-style API. Now with a flow document emitter.
Generate PDF/SVG/HTML with D, with a Canvas-style API. Now with a flow document emitter.
Need:
When trying to build my dub project depending on this package (0.0.9) , I get the error:
Non-optional dependency printed:image of printed not found in dependency tree!?.
Looking at the package format, I see:
"dependencies":
{
"printed:canvas": "*",
"printed:font": "*",
"printed:image": "*"
},
But the sub-packages are named font
, canvas
and htmlcolors
, not image
. Is the package description incorrect or am I doing something wrong?
I am trying to add some more functionality and fix the reported issues in my own code base so I don't depend on your immediate implementation. However, I am facing the issue that most of the methods and properties in the *Document
classes are marked as private
. This effectively forces me to copy&paste your code to make my changes.
It would be very easy to extend your code if the methods were protected
instead. For example I want to add the setLineDash
and lineDashOffset
methods/properties to the renderers.
This would lead to incorrect font selection.
I think base render api must provide functions for getting metrics of text with selected style (font, size etc) like a width and height of string (may be more metrics).
FreeType provides width
, height
, horiBearingX
, horiBearingY
, horiAdvance
, vertBearingX
, vertBearingY
, vertAdvance
about glyph.
https://www.freetype.org/freetype2/docs/tutorial/step2.html
It's useful for develop highlevel libraries for example for rendering TeX formulas, tables with text and etc.
because some glyph parsed from cmap don't exist, higher than numGlyphs
SVG coordinates have 0 on top which is more common, PDF is like OpenGL it has 0 on bottom.
Flip things vertically in PDF, but text direction should stay right.
Adobe Acrobat reader warns that "something is wrong in the PDF"
PDF prints and displays in the print dialog without text.
Browsers can display it fine.
Fonts like Jolt have a platformID == 3 and encodingID == 0
and we don't find the glyph '/' in it, though it does exist
Some parser choose table in reverse order.
Apple has lots of recommendations on selecting one cmap subtable.
stb_truetype doesn't seem to do anything in particular.
Many font parsers support more than just format 4
TextMetrics.actualBoundingBoxLeft
TextMetrics.actualBoundingBoxRight
TextMetrics.actualBoundingBoxWidth
right
alignmentend
alignmentstart
vs left
alignmentRemove the many, many virtual functions of IFlowDocument
with a DOM interface IDOMElement
that abstracts the DOM API (the problem is with things like <img src="path.png" />
, must query the tag inside FlowDocument. This is a breaking API change unless we also keep the tag callback (this allows direct Markdown to PDF generation... so not sure).
Since the one in gamut can export to PNG or JPEG
Going through files can result in atomicity problems in webservers rendering to PDF
At the same time, gamut JPEG encoder will never do better than specialized JPEG encoders
Another possibility is to take a Gamut image directly
Lately, I ran into the problem of missing font glyphs. The missing glyphs are for default ASCII characters like 'I' or '9'. Which glyphs are missing depends on the selected font, e.g. 'I' is "missing" in Open Sans and '9' is missing in Helvetica. I tried debugging the thing but I only found out that the characters in question are not in the _charToGlyphMapping
table.
Can you help? I attached the Open Sans TTF files from my system in case you want to try reproducing the bug.
This will allow to use Unicode codepoints values directly in text instead of glyph indices, thus speeding up generation.
This will allow make copy-pasting of text work: it expect CID to be unicode codepoint in most viewers.
CIDToGIDMap
parsing the OpenType fontDid it change with downgrading to PDF 1.4?
The current implementation of SVGDocument.restore()
pops the entire stack but all other operations on the stack just push a single element/group onto it.
I am irritated by this behavior and would expect that it pops all elements until the level that save()
was called is reached. Is the current behavior intended? I am no PDF expert but to me it looks like the PDFDocument
has a different implementation that acts more like my expectation.
Here is an example of what I would like to do: Draw several objects into a "content area" of the page which is the page minus some padding on all sides. I would try to do it like this:
enum paddingTop = 42f;
enum paddingLeft = 42f;
renderer.translate(paddingLeft, paddingTop);
renderer.save();
// plot object1
// plot object2
// ...
renderer.restore();
But if I use the save/restore
pattern inside one of the objects, the rest will not be transformed by the initial translate.
I created a PDF using this library and printing from Chrome to the printer, print in blank.
Any help?
output.pdf
Currently => 100% opaque all the time.
The way to solve it is that for all 256 possible alpha, have a lazy Graphics State Parameters state with autogenerated names, to be used in the content stream with the gs
operator.
Do that for stroke alpha and fill alpha.
When importing the printed
package into the project the DUB (or the compiler?) issues a warning that the source path is invalid. I think it originates from splitting the package into several sub-packages and should be pretty easy to fix by clearing these paths in dub.json
: "importPaths": [], "sourcePaths": []
importing of arsd-official:nanovega makes printed to print blank pages only. Tested under Ubuntu 18.04
HTML and TeX starts from a complete description of a document to be able to render it. I think it's overkill and we can use a simpler "flow" layout, where declarative is minimal.
The flow renderer would be built upon CanvasRenderer2D, and you can get the inner CanvasRenderer2D in order to put some flow elements.
It can layout then render whole paragraphs, whose text could contain bold or italic text.
Which implies it can break text into breakable components. Hyphenation will probably not be supported.
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/textBaseline
Firefox and Chrome renders them differently, Chrome looks more correct.
The goal is to compare the PDF output to something else, and to clarify the operation specifications on a renderer (IRenderingContext2D
).
A lot of it is copied from the HTML 5 Canvas API, which is nice to use.
SVGDocument.strokeRect
ignores the lineWidth
but it should set the stroke-width
attribute of the <rect>
element accordingly.
Current functions do both. Should be separate functions. Spec to follow.
Someone has a clue here:
https://stackoverflow.com/questions/128162/unicode-in-pdf
Algoman's answer is wrong in many things. You can make a PDF documents with unicode in it' and it's not a rocket science, though it needs some work. Yes he is right, to use more than 255 characters in one font you have to create a composite font (CIDFont) pdf object. Then you just mention the actual TrueType font you want to use as a DescendatFont entry of CIDFont. The trick is that after that you have to use glyph indices of a font instead of character codes. To get this indices map you have to parse cmap section of a font - get contents of the font with GetFontData function and take hands on TTF specification. And that's it! I've just did it and now I have a unicode pdf! Sample Code for parsing cmap section is here: https://support.microsoft.com/en-us/kb/241020 And yes, don't forget /ToUnicode entry as @user2373071 pointed out or user will not be able to search your PDF or copy text from it.
In your example I try different fonts:
fontFace("Helvetica");
fontFace("Courier");
fontFace("Comic Sans");
but the output doesn't change.
Thank you
$ cd printed/
$ git describe --tags 128 (0.014s) < v1.0.5
$ cd example/simple
$ dub run -q 0 (0.001s) < 08:32:51
core.exception.RangeError@../../font/printed/font/opentype.d(394): Range violation
----------------
??:? _d_arrayboundsp [0x5651707c0095]
../../font/printed/font/opentype.d:394 int printed.font.opentype.OpenTypeFont.horizontalAdvance(dchar) [0x56517079f0e7]
../../font/printed/font/opentype.d:442 int printed.font.opentype.OpenTypeFont.measureText(immutable(char)[]).__foreachbody4(ref dchar) [0x56517079f2d3]
??:? _aApplycd1 [0x5651707c07e1]
../../font/printed/font/opentype.d:441 printed.font.opentype.OpenTypeTextMetrics printed.font.opentype.OpenTypeFont.measureText(immutable(char)[]) [0x56517079f292]
../../canvas/printed/canvas/pdfrender.d:158 void printed.canvas.pdfrender.PDFDocument.fillText(immutable(char)[], float, float) [0x565170769c9d]
source/app.d:69 _Dmain [0x565170756ae6]
Program exited with code 1
Maybe depends on #25?
Thank you
dub build -q
Invalid source/import path: /home/o3o/.dub/packages/printed-1.0.1/printed/source
Invalid source/import path: /home/o3o/.dub/packages/printed-1.0.1/printed/source
Configuration 'library' of package printed contains no source files. Please add {"targetType": "none"} to its package description to avoid building it.
Invalid source/import path: /home/o3o/.dub/packages/printed-1.0.1/printed/source
Invalid source/import path: /home/o3o/.dub/packages/printed-1.0.1/printed/source
My dub file:
cat dub.sdl
name "printed_test"
description "A minimal D application."
dependency "printed" version="~>1.0.1"
Thank you
Not sure if correct.
Goal: follow CSS Color Module Level 4
Remaining:
hsl
and hsla
How does it work in browsers?
Add ability to embed a PNG or JPEG image directly.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.