Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
paintingapage [2015/04/02 14:39] christian [Painting Text] |
paintingapage [2017/10/05 12:54] (current) christian [Hello World - How text gets onto a page] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== How does text get onto a PDF page ====== | + | ====== How text gets onto a page ====== |
A PDF page has a content stream (**''/ | A PDF page has a content stream (**''/ | ||
Line 25: | Line 25: | ||
To achieve this in Smalltalk you can write the following: | To achieve this in Smalltalk you can write the following: | ||
<code smalltalk> | <code smalltalk> | ||
- | page := Page newInBounds: | + | page := Page newInBounds: |
renderer fillColor: CmykColor black. | renderer fillColor: CmykColor black. | ||
renderer textObjectDo: | renderer textObjectDo: | ||
Line 32: | Line 32: | ||
renderer showString: 'Hello World' | renderer showString: 'Hello World' | ||
</ | </ | ||
+ | {{pdf: | ||
+ | |||
You notice that I did not use the font ID **''/ | You notice that I did not use the font ID **''/ | ||
The renderer you get when creating a Page takes care of the **''/ | The renderer you get when creating a Page takes care of the **''/ | ||
- | Common operators are implemented as renderer methods like **'' | + | Common operators are implemented as renderer methods like **'' |
**'' | **'' | ||
Line 94: | Line 96: | ||
The implementation may look at bit clumsy. Why should you use | The implementation may look at bit clumsy. Why should you use | ||
<code smalltalk> | <code smalltalk> | ||
- | renderer add: (TextPositioningOperator Td operands: #(10 5)) | + | renderer add: (NextLineRelative |
</ | </ | ||
- | to get the simple string | + | to get the simple string |
- | Firstly, I wanted operators as objects and not just as strings you write into the contents stream. The objects can be read from a PDF (try: from the PDFExplorer | + | Firstly, I wanted operators as objects and not just as strings you write into the contents stream. The objects can be read from a PDF (try: from the [[pdf: |
- | * check the consistency/ | + | * check the consistency/ |
* implement a GraphicsState object to track the changes to it. With this, unneccessary operators can be avoided (this is on my todo list). | * implement a GraphicsState object to track the changes to it. With this, unneccessary operators can be avoided (this is on my todo list). | ||
In any case, it is good to have operators referable in the development image. | In any case, it is good to have operators referable in the development image. | ||
- | |||
- | Operators have a name and arguments, the operands. There are subclasses for each group of operators. They don't add state, but allow for different behavior (which is not exploited yet). An operator is created by sending the appropriate class message to the corresponding Operator class. | ||
- | <code smalltalk> | ||
- | TextPositioningOperator Td | ||
- | </ | ||
- | The operands are added with | ||
- | <code smalltalk> | ||
- | < | ||
- | </ | ||
- | which returns a copy of the operator with the operands. | ||
- | |||
- | I am not sure that this design will stand the time. I will see when I use it in ernest. | ||
Secondly, this clumsy interface is meant to be used as backend by a higher level graphics framework. It is expected that you have an abstraction of **Text** which can render itself using the PDF primitives. In [[http:// | Secondly, this clumsy interface is meant to be used as backend by a higher level graphics framework. It is expected that you have an abstraction of **Text** which can render itself using the PDF primitives. In [[http:// | ||
Line 145: | Line 135: | ||
I like to develop my abstractions from the bottom up and try to keep them as simple as possible. Maybe, over time, users will develop abstractions which are generally useful. In the end it should be a community discussion and consensus of what should be included. So far, only the bare metal on the spec will be available and you have to evolve your own abstractions. | I like to develop my abstractions from the bottom up and try to keep them as simple as possible. Maybe, over time, users will develop abstractions which are generally useful. In the end it should be a community discussion and consensus of what should be included. So far, only the bare metal on the spec will be available and you have to evolve your own abstractions. | ||
- | ==== Comments ==== | + | ===== Comments |
- | === Higher level abstractions === | + | ==== Higher level abstractions |
Submitted by bobcalco on Tue, 2012-01-24 10:32. | Submitted by bobcalco on Tue, 2012-01-24 10:32. | ||
Line 159: | Line 149: | ||
I know about this because I used an earlier version of Prawn to code a PDF generation feature of a content delivery system, which I am now needing to replace in Smalltalk, having decided to make the switch. I am a bit sad at the state of PDF generation in Smalltalk. There are so many other strengths in Smalltalk for the kind of distributed system I am building that wooed me over, but this deficiency is going to cost me some late nights and lamp oil. | I know about this because I used an earlier version of Prawn to code a PDF generation feature of a content delivery system, which I am now needing to replace in Smalltalk, having decided to make the switch. I am a bit sad at the state of PDF generation in Smalltalk. There are so many other strengths in Smalltalk for the kind of distributed system I am building that wooed me over, but this deficiency is going to cost me some late nights and lamp oil. | ||
- | === Here is a PDF manual === | + | ==== Here is a PDF manual |
Submitted by bobcalco on Tue, 2012-01-24 12:03. | Submitted by bobcalco on Tue, 2012-01-24 12:03. | ||
Line 167: | Line 157: | ||
http:// | http:// | ||
- | === Re: Higher level abstractions === | + | ==== Re: Higher level abstractions |
Submitted by ChristianHaider on Tue, 2012-01-24 11:58. | Submitted by ChristianHaider on Tue, 2012-01-24 11:58. | ||
Line 173: | Line 163: | ||
Interesting. I am curious what experiences you have while porting from Prawn to PDF4Smalltalk. Maybe some good concepts can be integrated... If you have any questions, please ask in the forum - sometimes I am responsive :-) | Interesting. I am curious what experiences you have while porting from Prawn to PDF4Smalltalk. Maybe some good concepts can be integrated... If you have any questions, please ask in the forum - sometimes I am responsive :-) | ||
- | === Thanks! === | + | ==== Thanks! |
Submitted by bobcalco on Tue, 2012-01-24 12:06. | Submitted by bobcalco on Tue, 2012-01-24 12:06. |