1 18 package org.apache.batik.gvt.flow; 19 20 import java.awt.font.FontRenderContext ; 21 import java.awt.font.TextAttribute ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 import java.util.Map ; 25 26 import org.apache.batik.gvt.font.FontFamilyResolver; 27 import org.apache.batik.gvt.font.GVTFont; 28 import org.apache.batik.gvt.font.GVTFontFamily; 29 import org.apache.batik.gvt.font.GVTLineMetrics; 30 import org.apache.batik.gvt.font.UnresolvedFontFamily; 31 32 public class BlockInfo { 33 public final static int ALIGN_START = 0; 34 public final static int ALIGN_MIDDLE = 1; 35 public final static int ALIGN_END = 2; 36 public final static int ALIGN_FULL = 3; 37 38 protected float top; 39 protected float right; 40 protected float bottom; 41 protected float left; 42 43 protected float indent; 44 45 protected int alignment; 46 47 protected float lineHeight; 48 protected List fontFamilyList; 49 protected Map fontAttrs; 50 protected float ascent=-1; 51 protected float descent=-1; 52 53 protected boolean flowRegionBreak; 54 55 56 public BlockInfo(float top, float right, float bottom, float left, 57 float indent, int alignment, float lineHeight, 58 List fontFamilyList, Map fontAttrs, 59 boolean flowRegionBreak) { 60 this.top = top; 61 this.right = right; 62 this.bottom = bottom; 63 this.left = left; 64 65 this.indent = indent; 66 67 this.alignment = alignment; 68 69 this.lineHeight = lineHeight; 70 this.fontFamilyList = fontFamilyList; 71 this.fontAttrs = fontAttrs; 72 73 this.flowRegionBreak = flowRegionBreak; 74 } 75 76 public BlockInfo(float margin, int alignment) { 77 setMargin(margin); 78 this.indent = 0; 79 this.alignment = alignment; 80 this.flowRegionBreak = false; 81 } 82 83 public void setMargin(float margin) { 84 this.top = margin; 85 this.right = margin; 86 this.bottom = margin; 87 this.left = margin; 88 } 89 90 public void initLineInfo(FontRenderContext frc) { 91 float fontSize = 12; 92 Float fsFloat = (Float )fontAttrs.get(TextAttribute.SIZE); 93 if (fsFloat != null) 94 fontSize = fsFloat.floatValue(); 95 96 Iterator i = fontFamilyList.iterator(); 97 while (i.hasNext()) { 98 GVTFontFamily fontFamily = (GVTFontFamily)i.next(); 99 if (fontFamily instanceof UnresolvedFontFamily) { 100 fontFamily = FontFamilyResolver.resolve 101 ((UnresolvedFontFamily)fontFamily); 102 } 103 if (fontFamily == null) continue; 104 105 106 GVTFont font = fontFamily.deriveFont(fontSize, fontAttrs); 107 GVTLineMetrics lm = font.getLineMetrics("", frc); 108 this.ascent = lm.getAscent(); 109 this.descent = lm.getDescent(); 110 break; 111 } 112 if (ascent == -1) { 113 ascent = fontSize * .8f; 114 descent = fontSize * .2f; 115 } 116 } 117 118 public float getTopMargin() { return top; } 119 public float getRightMargin() { return right; } 120 public float getBottomMargin() { return bottom; } 121 public float getLeftMargin() { return left; } 122 123 public float getIndent() { return indent; } 124 125 public int getTextAlignment() { return alignment; } 126 127 128 public float getLineHeight() { return lineHeight; } 129 public List getFontFamilyList() { return fontFamilyList; } 130 public Map getFontAttrs() { return fontAttrs; } 131 public float getAscent() { return ascent; } 132 public float getDescent() { return descent; } 133 134 public boolean isFlowRegionBreak() { return flowRegionBreak; } 135 136 } 137 | Popular Tags |