def getScreen(self, ctrl, doExtra, partials=False, pageCache=None): cfgGui = ctrl.getCfgGui() textOp = pml.TextOp texts = [] dpages = [] width, height = ctrl.GetClientSizeTuple() # gap between pages (+ screen left/top edge), both vertical/ # horizontal (pixels) pageGap = 10 # how many columns and rows cols = max(1, (width - pageGap) // (ctrl.pageW + pageGap)) rows = max(1, (height - pageGap) // (ctrl.pageH + pageGap)) pageCnt = cols * rows pager = mypager.Pager(ctrl.sp.cfg) fi = config.FontInfo() fi.font = cfgGui.fonts[pml.NORMAL].font fi.fx = fi.fy = self.size mm2p = ctrl.mm2p pageNr = ctrl.sp.line2page(ctrl.sp.getTopLine()) pagesDone = 0 while 1: if (pagesDone >= pageCnt) or (pageNr >= len(ctrl.sp.pages)): break if pageCache: pg = pageCache.getPage(pager, pageNr) else: pg = ctrl.sp.generatePMLPage(pager, pageNr, False, doExtra) if not pg: break xi = pagesDone % cols yi = pagesDone // cols sx = pageGap + xi * (ctrl.pageW + pageGap) sy = pageGap + yi * (ctrl.pageH + pageGap) dp = DisplayPage(pageNr, sx, sy, sx + ctrl.pageW, sy + ctrl.pageH) dpages.append(dp) for op in pg.ops: if not isinstance(op, textOp): continue texts.append( TextString(op.line, op.text, int(sx + op.x * mm2p), int(sy + op.y * mm2p), fi, False)) pageNr += 1 pagesDone += 1 return (texts, dpages)
def getScreen(self, ctrl, doExtra, partials=False, pageCache=None): cfgGui = ctrl.getCfgGui() textOp = pml.TextOp texts = [] dpages = [] width, height = ctrl.GetClientSizeTuple() mm2p = ctrl.mm2p # gap between pages (+ screen left edge) pageGap = 10 # how many pages fit on screen pageCnt = max(1, (width - pageGap) // (ctrl.pageW + pageGap)) pager = mypager.Pager(ctrl.sp.cfg) topLine = ctrl.sp.getTopLine() pageNr = ctrl.sp.line2page(topLine) if doExtra and ctrl.sp.cfg.pdfShowSceneNumbers: pager.scene = ctrl.sp.getSceneNumber( ctrl.sp.page2lines(pageNr)[0] - 1) pagesDone = 0 while 1: if (pagesDone >= pageCnt) or (pageNr >= len(ctrl.sp.pages)): break # we'd have to go back an arbitrary number of pages to get an # accurate number for this in the worst case, so disable it # altogether. pager.sceneContNr = 0 if pageCache: pg = pageCache.getPage(pager, pageNr) else: pg = ctrl.sp.generatePMLPage(pager, pageNr, False, doExtra) if not pg: break sx = pageGap + pagesDone * (ctrl.pageW + pageGap) sy = pageGap dp = DisplayPage(pageNr, sx, sy, sx + ctrl.pageW, sy + ctrl.pageH) dpages.append(dp) for op in pg.ops: if not isinstance(op, textOp): continue texts.append( TextString(op.line, op.text, int(sx + op.x * mm2p), int(sy + op.y * mm2p), cfgGui.fonts[op.flags & 3], op.flags & pml.UNDERLINED)) pageNr += 1 pagesDone += 1 return (texts, dpages)
def getScreen(self, ctrl, doExtra, partials=False, pageCache=None): cfgGui = ctrl.getCfgGui() textOp = pml.TextOp texts = [] dpages = [] width, height = ctrl.GetClientSizeTuple() # gap between pages (pixels) pageGap = 10 pager = mypager.Pager(ctrl.sp.cfg) mm2p = ctrl.mm2p fontY = cfgGui.fonts[pml.NORMAL].fy cox = util.clamp((width - ctrl.pageW) // 2, 0) y = 0 topLine = ctrl.sp.getTopLine() pageNr = ctrl.sp.line2page(topLine) if doExtra and ctrl.sp.cfg.pdfShowSceneNumbers: pager.scene = ctrl.sp.getSceneNumber( ctrl.sp.page2lines(pageNr)[0] - 1) # find out starting place (if something bugs, generatePMLPage # below could return None, but it shouldn't happen...) if pageCache: pg = pageCache.getPage(pager, pageNr) else: pg = ctrl.sp.generatePMLPage(pager, pageNr, False, doExtra) topOfPage = True for op in pg.ops: if not isinstance(op, textOp) or (op.line == -1): continue if op.line == topLine: if not topOfPage: y = -int(op.y * mm2p) else: y = pageGap break else: topOfPage = False # create pages, convert them to display format, repeat until # script ends or we've filled the display. done = False while 1: if done or (y >= height): break if not pg: pageNr += 1 if pageNr >= len(ctrl.sp.pages): break # we'd have to go back an arbitrary number of pages to # get an accurate number for this in the worst case, # so disable it altogether. pager.sceneContNr = 0 if pageCache: pg = pageCache.getPage(pager, pageNr) else: pg = ctrl.sp.generatePMLPage(pager, pageNr, False, doExtra) if not pg: break dp = DisplayPage(pageNr, cox, y, cox + ctrl.pageW, y + ctrl.pageH) dpages.append(dp) pageY = y for op in pg.ops: if not isinstance(op, textOp): continue ypos = int(pageY + op.y * mm2p) if ypos < 0: continue y = max(y, ypos) if (y >= height) or (not partials and\ ((ypos + fontY) > height)): done = True break texts.append( TextString(op.line, op.text, int(cox + op.x * mm2p), ypos, cfgGui.fonts[op.flags & 3], op.flags & pml.UNDERLINED)) y = pageY + ctrl.pageH + pageGap pg = None # if user has inserted new text causing the script to overflow # the last page, we need to make the last page extra-long on # the screen. if dpages and texts and (pageNr >= (len(ctrl.sp.pages) - 1)): lastY = texts[-1].y + fontY if lastY >= dpages[-1].y2: dpages[-1].y2 = lastY + 10 return (texts, dpages)