34 Commits

Author SHA1 Message Date
Devon Govett
b36c548a0d Merge pull request #308 from ef4/continued-breaker
Avoid unnecessarily breaking inside words when using `continued`
2014-09-15 14:05:52 -04:00
Edward Faulkner
838afe15a0 Infinite loop when first word is longer than line 2014-09-12 16:25:12 -04:00
Edward Faulkner
1a5df016ce Avoid unnecessarily breaking inside words when using continued
`continued` is implemented by temporarily shortening the lineWidth,
which can cause the linewrapper to break inside words when that's not
really necessary.
2014-09-12 15:11:56 -04:00
Devon Govett
33920c3f2a Merge pull request #301 from ef4/center-spacing
Fix center-aligned character spacing
2014-09-11 19:51:10 -04:00
Edward Faulkner
3e19194802 Fix center-aligned character spacing 2014-09-11 16:09:54 -04:00
Edward Faulkner
5b433d808a fix indent with continued 2014-09-11 13:34:51 -04:00
Devon Govett
a6f6f4df8a Don't use trimRight since it isn't supported in IE 2014-04-14 09:58:26 -07:00
Devon Govett
1305a9592a Switch to 2 space indentation 2014-03-23 12:25:09 -07:00
Devon Govett
4257e69e07 Fix typo 2014-02-19 12:02:57 -08:00
Devon Govett
8139b4fa30 Add missing word count 2014-02-19 12:02:53 -08:00
Darius Kazemi
d7336a4bd0 "Dangling" single word lines now get emitted
This commit adds an extra emit to a required line break if there's a "dangling" word on the end.
2014-02-19 14:54:47 -05:00
Darius Kazemi
6637dca8eb Correcting for edge case in line wrapping
If you look at the flow of the `eachWord` function, you'll notice that we add the word to the buffer if the width of the word `w` is less than the space available.

There's an edge case where `linebreaker` says that a line break is required on a word (because of a manual break: `theword\n`) and the width of the word being considered is greater than `spaceLeft`. In the current pdfkit, if this is the case:

 * we do not append the word to the buffer
 * we emit the line
 * we break and move on to the next line, starting with a clean line

This omits the word entirely.

This commit makes it so that we only break the line and start with a clean line if we already had the space to write the line to the buffer. Otherwise, we append the word to the buffer and go to a new line.
2014-02-19 13:38:50 -05:00
Devon Govett
415d5a371a Reset continuedX if there is more than one line 2014-02-17 13:53:39 -08:00
Devon Govett
7fdc3b8d14 Fix for multiple continuations on the same line 2014-02-17 13:35:49 -08:00
Devon Govett
00c6dabf3c Stop wrapping text after filling specified height, and add ellipsis option. Fixes #149.
No longer makes new pages after user specified heights, but still does so if no height is given (page edge by default). This works with multiple columns too. It will fill the columns in the horizontal and vertical space provided and then stop, rather than going to a new page.

Also adds the `ellipsis` option which can be used to append an ellipsis character like `…` to the end of the cut off text. If you set `ellipsis: true`, it will use the default ellipsis character, but you can also set the option to any string you want to use.
2014-02-16 20:08:19 -08:00
Devon Govett
087f3f4aca Reset the X position to the starting X after line wrapping is done (unless continued) 2014-02-16 18:33:39 -08:00
Devon Govett
da593f077f Force break words that are longer than the entire line into pieces. Fixes #159. 2014-02-16 15:55:41 -08:00
Devon Govett
5a74677c66 Store continuedX on the line wrapper instead of the document, since the line wrapper is now reused 2014-02-16 14:48:40 -08:00
Devon Govett
7fafa309b8 Use the same line wrapper instance when text is continued, fixes multicolumns 2014-02-16 14:41:26 -08:00
Devon Govett
50b6bab177 Make sure we don't pass the maximum Y position 2014-02-16 13:17:45 -08:00
Devon Govett
670bb09bf7 Reset X position to start on new page (fix for columns) 2014-02-16 13:07:24 -08:00
Devon Govett
ebeca3c680 Add continued option to text so that text with inline styles can be created. Closes #60, #180, #189.
The following example adds text with three sections (part1, part2, part3) in different fonts and colors.

doc.font('Helvetica', 13)
   .text(part1, 100, 300, { continued: yes, indent: 50 })
   .fillColor('red')
   .text(part2, { indent: 50, continued: yes })
   .font('Times', 13)
   .fillColor('green')
   .text(part3)
2014-02-16 11:56:31 -08:00
Devon Govett
9d22de6068 Fix textWidth 2014-02-16 11:52:10 -08:00
Devon Govett
abc871feda Fix indent 2014-02-16 11:51:46 -08:00
Devon Govett
4b3d2c9e30 Save the fill color and restore it after the line wrapper makes a new page 2014-02-16 11:50:59 -08:00
Devon Govett
ef6578a486 Rewrite the line wrapper to use an implementation of the Unicode Line Breaking Algorithm
Should solve a huge number of issues. The regular express based word matching from before was not good. It was overzealous and caused the most bugs of anything in the project. It also didn't work at all for languages like Chinese which don't have spaces between words.

The new wrapping algorithm supports all of this. It is a separate module at http://github.com/devongovett/linebreak.
2014-02-16 02:00:18 -08:00
Devon Govett
897630ecb9 Fix some issues with indentation in the line wrapper 2014-02-16 01:56:25 -08:00
yonishostak
8b3cc99033 make the last commit an actually valid coffescript 2014-02-11 15:51:06 -05:00
yonishostak
0af7aefc13 fix issue #195 in pdfkit repo 2014-02-11 12:13:41 -05:00
Nathanael Anderson
3e158edc98 Fixes the invalid calculation of page size in Line Wrapper.
@startY + options.height will actually = the full remainder of the page, by subrtacting out a line of text it just wrapped a line of text too early as the last line of text could never fit.
2013-12-03 14:21:29 -06:00
Devon Govett
d2b728fdff Merge pull request #152 from Nathanaela/Text_Wrapping_Fix
Fix bug in Line_Wrapper ignoring \n in most cases.  (Causes text wrapping to be wrong)
2013-11-09 22:45:37 -08:00
Nathanael Anderson
e5bbe4dfce Fixes the eating of prefix characters:
;:.-/\?!
2013-10-24 12:43:25 -05:00
Nathanael Anderson
933aee7d60 Fix bug in Line_Wrapper ignoring \n in most cases. (Causes text wrapping to be wrong) 2013-08-14 09:35:30 -05:00
Devon Govett
bf760a1729 Break line wrapper out into separate class 2013-05-12 20:24:51 -07:00