From 5257a98d88f73ce40b9f39caef5bb4146e765ed2 Mon Sep 17 00:00:00 2001 From: ketmar Date: Wed, 3 Aug 2016 07:24:46 +0000 Subject: [PATCH] cosmetix FossilOrigin-Name: 383bd9f41a895e5c6ea4b1634aa1bdaf4f459d62bf9a0fd19d6ccd614be86e8d --- booktext.d | 4 +--- xlayouter.d | 45 +++++++++++++++++++++++---------------------- xreader.d | 4 +--- xreadercfg.d | 4 +--- xreaderfmt.d | 4 +--- xreaderifs.d | 4 +--- xreaderui.d | 4 +--- 7 files changed, 29 insertions(+), 40 deletions(-) diff --git a/booktext.d b/booktext.d index 295e8f9..f96641b 100644 --- a/booktext.d +++ b/booktext.d @@ -18,9 +18,7 @@ module booktext /*is aliced*/; import std.encoding; -import arsd.color; -import arsd.png; -import arsd.jpeg; +import arsd.image; import iv.encoding; import iv.iresample; diff --git a/xlayouter.d b/xlayouter.d index bd0b4d5..46de000 100644 --- a/xlayouter.d +++ b/xlayouter.d @@ -16,9 +16,7 @@ */ module xlayouter; -import arsd.color; -import arsd.png; -import arsd.jpeg; +import arsd.image; import iv.nanovg; import iv.nanovg.oui.blendish; @@ -118,6 +116,7 @@ public: } } + // returns "font id" which can be used in `fontFace()` @property int fontFaceId (const(char)[] name) { if (auto fid = name in fontfaces) return *fid; return -1; @@ -154,6 +153,8 @@ public: return lrintf(it.advance*count); } + // this returns "width", "width with trailing whitespace", and "width with trailing hypen" + // all `*` args can be omited void textWidth2(T) (const(T)[] str, int* w=null, int* wsp=null, int* whyph=null) if (is(T == char) || is(T == dchar)) { import std.algorithm : max; if (w is null && wsp is null && whyph is null) return; @@ -210,7 +211,7 @@ align(1): Strike = 1<<2, Underline = 1<<3, Overline = 1<<4, - Href = 1<<5, + Href = 1<<5, // this is cross-reference (not actually a style flag, but it somewhat fits here) } ubyte flags; // see above int fontface = -1; // i can't use strings here, as this struct inside LayWord will not be GC-scanned @@ -253,7 +254,7 @@ align(1): Justify, } Justify mode = Justify.Left; - short lpad, rpad, tpad, bpad; + short lpad, rpad, tpad, bpad; // paddings; left and right can be negative ubyte paraIndent; // in spaces string toString () const { import std.format : format; @@ -307,8 +308,10 @@ align(1): Hypen = 1<<2, // if i'll break at this word, should i add hyphen mark? LineEnd = 1<<3, // this word ends current line ParaEnd = 1<<4, // this word ends current paragraph (and, implicitly, line) - Object = 1<<5, // dchar at wstart is actually object index in object array + Object = 1<<5, // wstart is actually object index in object array } + // note that if word is softhyphen candidate, i have hyphen mark at [wend] + // if props.hyphen is set, wend is including that mark, otherwise it isn't ubyte flags; // see above @property pure nothrow @safe @nogc: bool canbreak () const { pragma(inline, true); return ((flags&Flag.CanBreak) != 0); } @@ -322,8 +325,6 @@ align(1): bool paraend () const { pragma(inline, true); return ((flags&Flag.ParaEnd) != 0); } void paraend (bool v) { pragma(inline, true); if (v) flags |= Flag.ParaEnd; else flags &= ~Flag.ParaEnd; } bool someend () const { pragma(inline, true); return ((flags&(Flag.ParaEnd|Flag.LineEnd)) != 0); } - // note that if word is softhyphen candidate, i have hyphen mark at [wend] - // if props.hyphen is set, wend is including that mark, otherwise it isn't bool object () const { pragma(inline, true); return ((flags&Flag.Object) != 0); } void object (bool v) { pragma(inline, true); if (v) flags |= Flag.Object; else flags &= ~Flag.Object; } } @@ -445,17 +446,6 @@ private: } } } - - /* - void putChars (const(char)[] str...) { - import core.stdc.string : memcpy; - if (str.length == 0) return; - if (str.length >= int.max/2) throw new Exception("string too long"); - ensurePool!(16, false)(cast(uint)str.length, ltext, charsUsed, charsAllocated); - memcpy(ltext+charsUsed, str.ptr, str.length); - charsUsed += cast(uint)str.length; - } - */ } else { void putChars (const(dchar)[] str...) { import core.stdc.string : memcpy; @@ -550,7 +540,6 @@ private: public: int textHeight = 0; // total text height int textWidth = 0; // maximum text width - //int wordTag = 0; // you are free to change this public: // compare function should return (roughly): key-l @@ -592,6 +581,7 @@ public: return res; } + // find word at given coordinate in the given line int findWordAtX (LayLine* ln, int x) { int wcmp (int wnum) { auto w = words+ln.wstart+wnum; @@ -622,7 +612,7 @@ public: LayWord* wordByIndex (uint idx) pure nothrow @trusted @nogc { pragma(inline, true); return (idx < wordsUsed ? words+idx : null); } - @property const(TBT)[] wordText (in ref LayWord w) const pure nothrow @trusted @nogc { pragma(inline, true); return ltext[w.wstart..w.wend]; } + @property const(TBT)[] wordText (in ref LayWord w) const pure nothrow @trusted @nogc { pragma(inline, true); return (w.wstart <= w.wend ? ltext[w.wstart..w.wend] : null); } @property int lineCount () const pure nothrow @safe @nogc { pragma(inline, true); return cast(int)linesUsed; } @@ -692,9 +682,11 @@ public: // current word index @property uint nextWordIndex () const pure nothrow @safe @nogc { pragma(inline, true); return wordsUsed+hasWordChars; } + // use those to change current style. font style will take an effect on next char, line style on next line @property ref LayFontStyle fontStyle () pure nothrow @safe @nogc { pragma(inline, true); return newStyle; } @property ref LayLineStyle lineStyle () pure nothrow @safe @nogc { pragma(inline, true); return newJust; } + // return "font id" for the given font face @property int fontFaceId (const(char)[] name) { if (laf !is null) { int fid = laf.fontFaceId(name); @@ -703,11 +695,15 @@ public: throw new Exception("unknown font face '"~name.idup~"'"); } + // return font face for the given "font id" @property string fontFace (int fid) { pragma(inline, true); return (laf !is null ? laf.fontFace(fid) : null); } + // end current line void endLine () { put(EndLineCh); } + // end current paragraph void endPara () { put(EndParaCh); } + // add "object" into text -- special thing that knows it's dimensions void putObject (LayObject obj) { import std.algorithm : max, min; flushWord(); @@ -736,7 +732,7 @@ public: w.paraPad = -1; } - // add text to layouter + // add text to layouter; it is ok to mix (valid) utf-8 and dchars here void put(T) (const(T)[] str...) if (is(T == char) || is(T == dchar)) { if (str.length == 0) return; @@ -831,12 +827,15 @@ public: } } + // "finalize" layout: calculate lines, layout words... + // call this after you done feeding text to this void finalize () { flushWord(); lastWasSoftHypen = false; relayout(maxWidth, true); } + // relayout everything using the existing words void relayout (int newWidth, bool forced) { if (newWidth < 1) newWidth = 1; if (!forced && newWidth == maxWidth) return; @@ -865,6 +864,7 @@ public: } public: + // don't use void save (VFile fl) { fl.rawWriteExact("XLL0"); fl.rawWriteExact(ltext[0..charsUsed]); @@ -872,6 +872,7 @@ public: } public: + // don't use void dump (VFile fl) const { fl.writeln("LINES: ", linesUsed); foreach (immutable idx, const ref ln; lines[0..linesUsed]) { diff --git a/xreader.d b/xreader.d index 58dbab6..ce3b2d0 100644 --- a/xreader.d +++ b/xreader.d @@ -21,9 +21,7 @@ import core.time; import std.concurrency; import arsd.simpledisplay; -import arsd.color; -import arsd.png; -import arsd.jpeg; +import arsd.image; import iv.nanovg; import iv.nanovg.oui.blendish; diff --git a/xreadercfg.d b/xreadercfg.d index a03d668..14ff752 100644 --- a/xreadercfg.d +++ b/xreadercfg.d @@ -17,9 +17,7 @@ module xreadercfg; import arsd.simpledisplay; -import arsd.color; -import arsd.png; -import arsd.jpeg; +import arsd.image; import iv.nanovg; import iv.strex; diff --git a/xreaderfmt.d b/xreaderfmt.d index cf6fa13..2d7b22c 100644 --- a/xreaderfmt.d +++ b/xreaderfmt.d @@ -23,9 +23,7 @@ import std.concurrency; import iv.strex; import arsd.simpledisplay; -import arsd.color; -import arsd.png; -import arsd.jpeg; +import arsd.image; import iv.nanovg; import iv.nanovg.oui.blendish; diff --git a/xreaderifs.d b/xreaderifs.d index 4b28ba5..6964c42 100644 --- a/xreaderifs.d +++ b/xreaderifs.d @@ -17,9 +17,7 @@ module xreaderifs; import arsd.simpledisplay; -import arsd.color; -import arsd.png; -import arsd.jpeg; +import arsd.image; import iv.nanovg; diff --git a/xreaderui.d b/xreaderui.d index 0a1eca6..d88bd94 100644 --- a/xreaderui.d +++ b/xreaderui.d @@ -17,9 +17,7 @@ module xreaderui; import arsd.simpledisplay; -import arsd.color; -import arsd.png; -import arsd.jpeg; +import arsd.image; import iv.nanovg; import iv.nanovg.oui.blendish; -- 2.11.4.GIT