浏览代码

Some more work on header footer params

Antialize 16 年之前
父节点
当前提交
0e28196377
共有 2 个文件被更改,包括 36 次插入13 次删除
  1. 32 13
      src/outline.cc
  2. 4 0
      src/outline_p.hh

+ 32 - 13
src/outline.cc

@@ -126,31 +126,50 @@ void Outline::addWebPage(const QString & name, QWebPrinter & wp, QWebFrame * fra
 	d->pageCount += wp.pageCount();
 }
 
+
+void OutlinePrivate::buildHFCache(OutlineItem * i, int level) {
+	if (level >= hfCache.size()) return;
+	foreach (OutlineItem * j, i->children) {
+		while (hfCache[level].size() < j->page)
+			hfCache[level].push_back(hfCache[level].back());
+		
+		if (hfCache[level].size() == j->page) 
+			hfCache[level].push_back(j);
+		buildHFCache(j, level+1);
+	}
+}
+
+
+
 /*!
   \brief Fill in header footer parameters for a given page
   \param page The page to fill in for
   \param parms The structure to fill
  */
 void Outline::fillHeaderFooterParms(int page, QHash<QString, QString> & parms) {
+	//Build hfcache
+	if (d->hfCache.size() == 0) {
+		for(int i=0; i < 3; ++i) {
+			QList< OutlineItem *> x;
+			x.push_back(NULL);
+			d->hfCache.push_back(x);
+		}
+		foreach (OutlineItem * i, d->documentOutlines) 
+			d->buildHFCache(i, 0);
+	}
+	for(int i=0; i < 3; ++i)
+		while(d->hfCache[i].size() <= page) 
+			d->hfCache[i].push_back(d->hfCache[i].back());
+
 	int off = d->settings.pageOffset;
 	parms["frompage"] = QString::number(off);
 	parms["topage"] = QString::number(off+d->pageCount-1);
 	parms["page" ] = QString::number(page+off);
 	parms["webpage"] = "foobar";
 
-//  	QString sec[TocPrinter::levels];
-// 	for (uint i=0; i < TocPrinter::levels; ++i) {
-// 		QMap<int, TocItem*>::const_iterator j = tocPrinter.page2sectionslow[i].find(pageNum);
-// 		if (j == tocPrinter.page2sectionslow[i].end()) {
-// 			j = tocPrinter.page2sectionshigh[i].upperBound(pageNum);
-// 			--j;
-// 			if (j == tocPrinter.page2sectionshigh[i].end()) continue;
-// 		}
-// 		sec[i] = j.value()->value;
-// 	}
-// 	res["section"] = sec[0];
-// 	res["subsection"] = sec[1];
-// 	res["subsubsection"] = sec[2];
+	parms["section" ] = d->hfCache[0][page]?d->hfCache[0][page]->value:QString("");
+	parms["subsection" ] = d->hfCache[1][page]?d->hfCache[1][page]->value:QString("");
+	parms["subsubsection" ] = d->hfCache[2][page]?d->hfCache[2][page]->value:QString("");
 }
 
 /*!

+ 4 - 0
src/outline_p.hh

@@ -35,10 +35,14 @@ public:
 	QList<OutlineItem *> documentOutlines;
 	int pageCount;
 	int anchorCounter;
+
+	QList< QList< OutlineItem *> > hfCache;
+
 	OutlinePrivate(const Settings & settings);
 	~OutlinePrivate();
 	void fillChildAnchors(OutlineItem * item, QHash<QString, QWebElement> & anchors);
 	void outlineChildren(OutlineItem * item, QPrinter * printer, int level);
+	void buildHFCache(OutlineItem * i, int level);
 };
 
 #endif //__EXTENSIVE_WKHTMLTOPDF_QT_HACK__