// // 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 line = new ArrayList(); ArrayList width = new ArrayList(); ArrayList height = new ArrayList(); ArrayList depth = new ArrayList(); ArrayList xpos = new ArrayList(); ArrayList ypos = new ArrayList(); ArrayList attribute = new ArrayList(); ArrayList tlinelength = new ArrayList(); 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);}; } }