diff options
author | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2019-09-02 13:46:59 +0900 |
commit | e0c6872cf40896c7be36b11dcc744620f10adf1d (patch) | |
tree | 60335e10d2f4354b0674ec22d7b53f0f8abee672 /systems/android/hktex/HKtex2/src/worker4math/hktex2/ParagraphFormatting2.java |
Initial commit
Diffstat (limited to 'systems/android/hktex/HKtex2/src/worker4math/hktex2/ParagraphFormatting2.java')
-rw-r--r-- | systems/android/hktex/HKtex2/src/worker4math/hktex2/ParagraphFormatting2.java | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/systems/android/hktex/HKtex2/src/worker4math/hktex2/ParagraphFormatting2.java b/systems/android/hktex/HKtex2/src/worker4math/hktex2/ParagraphFormatting2.java new file mode 100644 index 0000000000..e5fbbc5e6a --- /dev/null +++ b/systems/android/hktex/HKtex2/src/worker4math/hktex2/ParagraphFormatting2.java @@ -0,0 +1,124 @@ +// +// Latex Project Public Licence (lppl1.3) applies +// Originally written by Kwanleung Tse +// First Release : 1st July, 2014 +// Last Update : 27th September, 2014 +// +// + +package worker4math.hktex2; + +import java.util.ArrayList; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Typeface; + + +public class ParagraphFormatting2 { + + public void paragraphformatting2(Canvas canvas, ParagraphBlock paragraphblock, Float pagelength, String paragraph, Integer tid, Float indent, String thisattribute, Typeface tf){ + + ArrayList<String> line = new ArrayList<String>(); + ArrayList<Float> width = new ArrayList<Float>(); + ArrayList<Float> height = new ArrayList<Float>(); + ArrayList<Float> depth = new ArrayList<Float>(); + ArrayList<Float> xpos = new ArrayList<Float>(); + ArrayList<Float> ypos = new ArrayList<Float>(); + ArrayList<String> attribute = new ArrayList<String>(); + ArrayList<Float> tlinelength = new ArrayList<Float>(); + Float linelength = 0.0f; + Boolean newfirstline = false; + + int i; + int j=0; + + int linenu=0; + int fontsize = Integer.parseInt(thisattribute.substring(1,4)); + + float linelength2 = 0; + Boolean newfirstline2=false;; + float spacelength = 0; + + float linelength1=0; + Paint textpaint = new Paint(); + textpaint.setColor(Color.BLACK); + textpaint.setTextSize(fontsize); + textpaint.setTypeface(tf); + + synchronized(this){paragraphblock.init(tid);} + spacelength=textpaint.measureText(" "); + + paragraph=paragraph.trim(); + String words[] = paragraph.split(" "); + String word=""; + newfirstline2=false; + int sizej = words.length; + j=0; + line.add("");linenu=0;width.add(0.0f);height.add((float)fontsize);depth.add(0.0f);xpos.add(indent);ypos.add(0.0f);attribute.add(thisattribute); + linelength2=indent; + for (i=0;j<=sizej-1;i++){ + word=words[j].trim(); + word=words[j]; + if (word.equals("")){j++;} else{ + String line2=line.get(linenu)+word; + + linelength1=linelength2; + linelength2=indent+textpaint.measureText(line2); + if (linelength2 > pagelength){ + if (linenu==0){newfirstline2=true;}; + linelength2=linelength1; + if (word.contains("-")){ + int sw=word.indexOf("-"); + String tword1=word.substring(0,sw+1); + String tword2=word.substring(sw+1); + + line2=line.get(linenu)+tword1; + linelength1=linelength2; + linelength2=indent+textpaint.measureText(line2); + if (linelength2 > pagelength){ + linelength2=linelength1; + line.add("");linenu++;width.add(0.0f);height.add((float)fontsize);depth.add(0.0f);xpos.add(0.0f);ypos.add(0.0f);attribute.add(thisattribute); + indent=0.0f; + line.set(linenu, word+" "); + linelength2=indent+textpaint.measureText(line.get(linenu)); + width.set(linenu, linelength2); + ypos.set(linenu, ypos.get(linenu-1)+fontsize); + } + else { + line.set(linenu,line.get(linenu)+tword1); + width.set(linenu, linelength2-indent); + line.add("");linenu++;width.add(0.0f);height.add((float)fontsize);depth.add(0.0f);xpos.add(0.0f);ypos.add(0.0f);attribute.add(thisattribute); + indent=0.0f; + line.set(linenu, tword2+" "); + linelength2=textpaint.measureText(line.get(linenu)); + width.set(linenu, linelength2); + ypos.set(linenu, ypos.get(linenu-1)+fontsize+Header.linegap); + }; + j++; + } else { + linelength2=linelength1; + line.add("");linenu++;width.add(0.0f);height.add((float)fontsize);depth.add(0.0f);xpos.add(0.0f);ypos.add(0.0f);attribute.add(thisattribute); + indent=0.0f; + line.set(linenu, word+" "); + linelength2=indent+textpaint.measureText(line.get(linenu)); + width.set(linenu, linelength2); + ypos.set(linenu, ypos.get(linenu-1)+fontsize); + j++; + } + }else{ + line.set(linenu,line.get(linenu)+word+" "); + linelength2=indent+textpaint.measureText(line.get(linenu)); + if (linenu==0 ){width.set(linenu, linelength2-indent);} else {width.set(linenu, linelength2);}; + j++;} + }} + linelength2=linelength2+spacelength;width.set(linenu, width.get(linenu)+spacelength); + + for (i=0;i<=linenu;i++){ + tlinelength.add(textpaint.measureText(line.get(i))); + } + linelength=linelength2; + newfirstline=newfirstline2; + synchronized(this){paragraphblock.add(tid, line, width, height, depth, xpos,ypos, attribute, tlinelength, linelength, newfirstline);}; + } +} |