~ubuntu-branches/debian/sid/calibre/sid

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/oeb/display/paged.coffee

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2014-05-14 18:17:50 UTC
  • mfrom: (1.5.10)
  • Revision ID: package-import@ubuntu.com-20140514181750-xyrxqa47dbw0qfhu
Tags: 1.36.0+dfsg-1
* New upstream release:
  - Fixes editing of metadata (Closes: #741638)

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 
9
9
log = window.calibre_utils.log
10
10
 
 
11
runscripts = (parent) ->
 
12
    for script in parent.getElementsByTagName('script')
 
13
        eval(script.text || script.textContent || script.innerHTML || '')
 
14
 
11
15
class PagedDisplay
12
16
    # This class is a namespace to expose functions via the
13
17
    # window.paged_display object. The most important functions are:
22
26
        this.set_geometry()
23
27
        this.page_width = 0
24
28
        this.screen_width = 0
 
29
        this.side_margin = 0
25
30
        this.in_paged_mode = false
26
31
        this.current_margin_side = 0
27
32
        this.is_full_screen_layout = false
28
33
        this.max_col_width = -1
 
34
        this.max_col_height = - 1
29
35
        this.current_page_height = null
30
36
        this.document_margins = null
31
37
        this.use_document_margins = false
71
77
            this.margin_top = this.document_margins.top or margin_top
72
78
            this.margin_bottom = this.document_margins.bottom or margin_bottom
73
79
            this.margin_side = this.document_margins.left or this.document_margins.right or margin_side
 
80
            this.effective_margin_top = this.margin_top
 
81
            this.effective_margin_bottom = this.margin_bottom
74
82
        else
75
83
            this.margin_top = margin_top
76
84
            this.margin_side = margin_side
77
85
            this.margin_bottom = margin_bottom
 
86
            this.effective_margin_top = this.margin_top
 
87
            this.effective_margin_bottom = this.margin_bottom
78
88
 
79
89
    handle_rtl_body: (body_style) ->
80
90
        if body_style.direction == "rtl"
117
127
            col_width = Math.max(100, ((ww - adjust)/n) - 2*sm)
118
128
        this.col_width = col_width
119
129
        this.page_width = col_width + 2*sm
 
130
        this.side_margin = sm
120
131
        this.screen_width = this.page_width * this.cols_per_screen
121
 
        this.current_page_height = window.innerHeight - this.margin_top - this.margin_bottom
122
132
 
123
133
        fgcolor = body_style.getPropertyValue('color')
124
134
 
142
152
        if c?.nodeType == 1
143
153
            c.style.setProperty('-webkit-margin-before', '0')
144
154
 
 
155
        this.effective_margin_top = this.margin_top
 
156
        this.effective_margin_bottom = this.margin_bottom
 
157
        this.current_page_height = window.innerHeight - this.margin_top - this.margin_bottom
 
158
        if this.max_col_height > 0 and this.current_page_height > this.max_col_height
 
159
            eh = Math.ceil((this.current_page_height - this.max_col_height) / 2)
 
160
            this.effective_margin_top += eh
 
161
            this.effective_margin_bottom += eh
 
162
            this.current_page_height -= 2 * eh
145
163
 
146
164
        bs.setProperty('overflow', 'visible')
147
 
        bs.setProperty('height', (window.innerHeight - this.margin_top - this.margin_bottom) + 'px')
 
165
        bs.setProperty('height', this.current_page_height + 'px')
148
166
        bs.setProperty('width', (window.innerWidth - 2*sm)+'px')
149
 
        bs.setProperty('margin-top', this.margin_top + 'px')
150
 
        bs.setProperty('margin-bottom', this.margin_bottom+'px')
 
167
        bs.setProperty('margin-top', this.effective_margin_top + 'px')
 
168
        bs.setProperty('margin-bottom', this.effective_margin_bottom+'px')
151
169
        bs.setProperty('margin-left', sm+'px')
152
170
        bs.setProperty('margin-right', sm+'px')
153
171
        for edge in ['left', 'right', 'top', 'bottom']
193
211
    create_header_footer: (uuid) ->
194
212
        if this.header_template != null
195
213
            this.header = document.createElement('div')
196
 
            this.header.setAttribute('style', "overflow:hidden; display:block; position:absolute; left:#{ this.side_margin }px; top: 0px; height: #{ this.margin_top }px; width: #{ this.col_width }px; margin: 0; padding: 0")
 
214
            this.header.setAttribute('style', "overflow:hidden; display:block; position:absolute; left:#{ this.side_margin }px; top: 0px; height: #{ this.effective_margin_top }px; width: #{ this.col_width }px; margin: 0; padding: 0")
197
215
            this.header.setAttribute('id', 'pdf_page_header_'+uuid)
198
216
            document.body.appendChild(this.header)
199
217
        if this.footer_template != null
200
218
            this.footer = document.createElement('div')
201
 
            this.footer.setAttribute('style', "overflow:hidden; display:block; position:absolute; left:#{ this.side_margin }px; top: #{ window.innerHeight - this.margin_bottom }px; height: #{ this.margin_bottom }px; width: #{ this.col_width }px; margin: 0; padding: 0")
 
219
            this.footer.setAttribute('style', "overflow:hidden; display:block; position:absolute; left:#{ this.side_margin }px; top: #{ window.innerHeight - this.effective_margin_bottom }px; height: #{ this.effective_margin_bottom }px; width: #{ this.col_width }px; margin: 0; padding: 0")
202
220
            this.footer.setAttribute('id', 'pdf_page_footer_'+uuid)
203
221
            document.body.appendChild(this.footer)
204
222
        if this.header != null or this.footer != null
224
242
            section = py_bridge.section()
225
243
        if this.header != null
226
244
            this.header.innerHTML = this.header_template.replace(/_PAGENUM_/g, pagenum+"").replace(/_TITLE_/g, title+"").replace(/_AUTHOR_/g, author+"").replace(/_SECTION_/g, section+"")
 
245
            runscripts(this.header)
227
246
        if this.footer != null
228
247
            this.footer.innerHTML = this.footer_template.replace(/_PAGENUM_/g, pagenum+"").replace(/_TITLE_/g, title+"").replace(/_AUTHOR_/g, author+"").replace(/_SECTION_/g, section+"")
 
248
            runscripts(this.footer)
229
249
 
230
250
    fit_images: () ->
231
251
        # Ensure no images are wider than the available width in a column. Note
501
521
                    continue
502
522
                deltax = Math.floor(this.page_width/25)
503
523
                deltay = Math.floor(window.innerHeight/25)
504
 
                cury = this.margin_top
505
 
                until cury >= (window.innerHeight - this.margin_bottom)
 
524
                cury = this.effective_margin_top
 
525
                until cury >= (window.innerHeight - this.effective_margin_bottom)
506
526
                    curx = left + this.current_margin_side
507
527
                    until curx >= (right - this.current_margin_side)
508
528
                        cfi = window.cfi.at_point(curx-window.pageXOffset, cury-window.pageYOffset)