From 79c2fa3094b97d7f314661a65d5ef6f1fa0667a1 Mon Sep 17 00:00:00 2001 From: ketmar Date: Thu, 8 Sep 2016 09:33:29 +0000 Subject: [PATCH] paragraphs consists of only one image tag now will be centered FossilOrigin-Name: eeef7dc4f6cfd5ee10103d25a0c1fa6ba83301db0aadda79d3271bb205c0e80d --- xreaderfmt.d | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/xreaderfmt.d b/xreaderfmt.d index 2e1078a..84e9972 100644 --- a/xreaderfmt.d +++ b/xreaderfmt.d @@ -331,10 +331,32 @@ public BookMetadata formatBook (BookText book, LayText lay) { fixFont(lay); } + bool onlyImagePara (Tag ct) { + if (ct is null) return false; + int count; + foreach (Tag tag; ct.children) { + if (tag.name.length == 0) { + // text + if (tag.text.xstrip.length != 0) return false; + continue; + } + if (count != 0 || tag.name != "image") return false; + ++count; + } + return (count == 1); + } + void putTagContents (Tag ct, int boldc=0, int italicc=0, int underc=0) { if (ct is null) return; saveTagId(ct); - foreach (Tag tag; ct.children) putParaContentInternal(tag, boldc, italicc, underc); + if (onlyImagePara(ct)) { + lay.pushStyles(); + scope(exit) lay.popStyles; + lay.lineStyle.setCenter; + foreach (Tag tag; ct.children) putParaContentInternal(tag, boldc, italicc, underc); + } else { + foreach (Tag tag; ct.children) putParaContentInternal(tag, boldc, italicc, underc); + } lay.endPara(); } -- 2.11.4.GIT