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

Several new features & bugfixes #202

Merged
merged 52 commits into from Feb 16, 2015
Merged

Several new features & bugfixes #202

merged 52 commits into from Feb 16, 2015

Conversation

jthoenes
Copy link
Contributor

This pull request groups several features and bug-fixes. We open it as one pull request, because we want to avoid merge conflicts during development.

Features:

  • Introduce new styling properties marginLeft, marginRight, marginTop, and marginBottom.
  • Add the capability to have switch of page orientation per page.
  • Adds an editorconfig.
  • Adding possibility to specify line height.
  • Access to internal pages array, to have better testing capabilities.
  • Dynamically control page breaks, for instance to avoid orphan childs.

Bug Fixes:

Introduce new styling properties marginLeft, marginRight, marginTop, and marginBottom.

An element in the document definition can now specify margin on any side individually. This allows to combine margins from different styles.

 {
  content: [
    {text: 'text with style 1', style: ['style1']},
    {text: 'text with style 2', style: ['style2']},
    {text: 'text with both styles', style: ['style1', 'style2']}
  ], 
  styles: {
   style1: {
       marginTop: 30
   }, 
   style2: {
       marginLeft: 20
    }
  }
}

Add the capability to have switch of page orientation per page.

This allows a document to switch between landscape and portrait in a document.

    {
      pageOrientation: 'portrait',
      content: [
        {text: 'Text on Portrait'},
        {text: 'Text on Landscape', pageOrientation: 'landscape', pageBreak: 'before'},
        {text: 'Text on Landscape 2', pageOrientation: 'portrait', pageBreak: 'after'},
        {text: 'Text on Portrait 2'},
      ]
    }

Important you need to specify a page break on the same node, to make sure the page can switch it's orientation.

Adds an editorconfig.

An .editorconfig file makes sure that coding conventions, especially whitespaces, are kept within each editor.

Adding possibility to specify line height.

A new style property lineHeight is now available.

    {
      content: [{text: 'this is a very long text', lineHeight: 1.5}]
    }

lineHeight is a relative value.

Access to internal pages array, to have better testing capabilities.

This allows writing integration test agains a array of pages in PDF Make.

pdfMake.createPdf(docDefinition)._getPages({}, function(pages){
  assert.equal(pages.length, 2);
});

Dynamically control page breaks, for instance to avoid orphan childs.

You can now specify a pageBreakBefore function, which can determine if a page break should be inserted before the page break. To implement a 'no orphan child' rule, this could like like this:

var dd = {
    content: [
       {text: '1 Headline', headlineLevel: 1},
       'Some long text of variable length ...',
       {text: '2 Headline', headlineLevel: 1},
       'Some long text of variable length ...',
       {text: '3 Headline', headlineLevel: 1},
       'Some long text of variable length ...',
    ],
  pageBreakBefore: function(currentNode, followingNodesOnPage, nodesOnNextPage, previousNodesOnPage) {
     return currentNode.headlineLevel === 1 && followingNodesOnPage.length === 0;
  }
}

If pageBreakBefore returns true, a page break will be added before the currentNode. Current node has the following information attached:

{
   id: '<as specified in doc definition>', 
   headlineLevel: '<as specified in doc definition>',
   text: '<as specified in doc definition>', 
   ul: '<as specified in doc definition>', 
   ol: '<as specified in doc definition>', 
   table: '<as specified in doc definition>', 
   image: '<as specified in doc definition>', 
   qr: '<as specified in doc definition>', 
   canvas: '<as specified in doc definition>', 
   columns: '<as specified in doc definition>', 
   style: '<as specified in doc definition>', 
   pageOrientation '<as specified in doc definition>',
   pageNumbers: [2, 3], // The pages this element is visible on (e.g. multi-line text could be on more than one page)
   pages: 6, // the total number of pages of this document
   stack: false, // if this is an element which encapsulates multiple sub-objects
   startPosition: {
     pageNumber: 2, // the page this node starts on
     pageOrientation: 'landscape', // the orientation of this page
     left: 60, // the left position
     right: 60, // the right position
     verticalRatio: 0.2, // the ratio of space used vertically in this document (excluding margins)
     horizontalRatio: 0.0  // the ratio of space used horizontally in this document (excluding margins)
   }
}

umairsiddique and others added 30 commits January 18, 2015 04:21
This is to avoid using the same type (normal, bold, italics,
bolditalics) every time a font is requested.

Fixes #162.
* can set {text: '', pageOrientation: 'landscape'} property on any content element
This essentially creates a page context.
- watermark
- header
- footer
- background
@bpampuch
Copy link
Owner

amazing work !!!

bpampuch added a commit that referenced this pull request Feb 16, 2015
Several new features & bugfixes
@bpampuch bpampuch merged commit 5a22eb8 into bpampuch:master Feb 16, 2015
@Wabbala
Copy link

Wabbala commented Feb 16, 2015

Hi guys,

When will be a new build? I am very eager to try out the new features!

Cheers

On 16 February 2015 at 22:42, bpampuch notifications@github.com wrote:

amazing work !!!


Reply to this email directly or view it on GitHub
#202 (comment).

@bpampuch
Copy link
Owner

Probably within a few minutes ;)

@bpampuch
Copy link
Owner

looks like it will have to wait, I keep geting "global leak detected" from mocha, I'll have to investigate it

@jthoenes
Copy link
Contributor Author

Hm, what command do you run to get this issue?

@bpampuch
Copy link
Owner

mocha tableProcessor.js in tests

@bpampuch
Copy link
Owner

and what I get is:

  1) TableProcessor should use the line colors function (regression #161):
     Error: global leak detected: l
      at Runner.checkGlobals (/usr/lib/node_modules/mocha/lib/runner.js:170:21)
      at Runner.<anonymous> (/usr/lib/node_modules/mocha/lib/runner.js:59:44)
      at Runner.emit (events.js:129:20)
      at /usr/lib/node_modules/mocha/lib/runner.js:401:14
      at Test.Runnable.run (/usr/lib/node_modules/mocha/lib/runnable.js:215:5)
      at Runner.runTest (/usr/lib/node_modules/mocha/lib/runner.js:344:10)
      at /usr/lib/node_modules/mocha/lib/runner.js:390:12
      at next (/usr/lib/node_modules/mocha/lib/runner.js:270:14)
      at /usr/lib/node_modules/mocha/lib/runner.js:279:7
      at next (/usr/lib/node_modules/mocha/lib/runner.js:227:23)
      at /usr/lib/node_modules/mocha/lib/runner.js:242:7
      at Hook.Runnable.run (/usr/lib/node_modules/mocha/lib/runnable.js:215:5)
      at next (/usr/lib/node_modules/mocha/lib/runner.js:236:10)
      at Immediate._onImmediate (/usr/lib/node_modules/mocha/lib/runner.js:247:5)
      at processImmediate [as _immediateCallback] (timers.js:358:17)

  2) TableProcessor header with nested table (issue #199) should not remove the repeatable of the outer table when nested table ends:
     TypeError: Cannot assign to read only property '_calcWidth' of *
      at /Users/bartoszpampuch/src/pdfmake/src/columnCalculator.js:81:20
      at Array.forEach (native)
      at Object.buildColumnWidths (/Users/bartoszpampuch/src/pdfmake/src/columnCalculator.js:80:16)
      at TableProcessor.beginTable (/Users/bartoszpampuch/src/pdfmake/src/tableProcessor.js:17:20)
      at Context.<anonymous> (/Users/bartoszpampuch/src/pdfmake/tests/tableProcessor.js:182:22)
      at Test.Runnable.run (/usr/lib/node_modules/mocha/lib/runnable.js:213:32)
      at Runner.runTest (/usr/lib/node_modules/mocha/lib/runner.js:344:10)
      at /usr/lib/node_modules/mocha/lib/runner.js:390:12
      at next (/usr/lib/node_modules/mocha/lib/runner.js:270:14)
      at /usr/lib/node_modules/mocha/lib/runner.js:279:7
      at next (/usr/lib/node_modules/mocha/lib/runner.js:227:23)
      at Immediate._onImmediate (/usr/lib/node_modules/mocha/lib/runner.js:247:5)
      at processImmediate [as _immediateCallback] (timers.js:358:17)

@jthoenes
Copy link
Contributor Author

Found and fixed the global leak: 77a895c

I also added the leak checking to the grunt test task, to make sure Travis CI catches it earlier. I was not able to reproduce 2).

@bpampuch What is in your mocha.opt?

@e00dan
Copy link

e00dan commented Feb 19, 2015

When will this land in bower package?

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

Successfully merging this pull request may close these issues.

Cannot turn bold off
6 participants