📄 textline.java
字号:
public int getMaxDescent(Graphics g)
{
if(g == null)
{
return 0;
} else
{
parseText(g);
return maxDescent;
}
}
public int getLeading(Graphics g)
{
if(g == null)
{
return 0;
} else
{
parseText(g);
return leading;
}
}
public void parseText(Graphics g)
{
TextState textstate = new TextState();
Stack stack = new Stack();
boolean flag = false;
if(lg != g)
parse = true;
lg = g;
if(!parse)
return;
parse = false;
width = 0;
leading = 0;
ascent = 0;
descent = 0;
height = 0;
maxAscent = 0;
maxDescent = 0;
if(text == null || g == null)
return;
list.removeAllElements();
if(font == null)
textstate.f = g.getFont();
else
textstate.f = font;
stack.push(textstate);
list.addElement(textstate);
FontMetrics fontmetrics = g.getFontMetrics(textstate.f);
for(int i1 = 0; i1 < text.length(); i1++)
{
char c = text.charAt(i1);
switch(c)
{
case 36: // '$'
if(++i1 < text.length())
textstate.s.append(text.charAt(i1));
break;
case 123: // '{'
int i = textstate.getWidth(g);
if(!textstate.isEmpty())
{
textstate = textstate.copyState();
list.addElement(textstate);
}
stack.push(textstate);
textstate.x += i;
break;
case 125: // '}'
int j = textstate.x + textstate.getWidth(g);
stack.pop();
textstate = ((TextState)stack.peek()).copyState();
list.addElement(textstate);
textstate.x = j;
break;
case 94: // '^'
int k = textstate.getWidth(g);
if(!textstate.isEmpty())
{
textstate = textstate.copyState();
list.addElement(textstate);
}
textstate.f = getScriptFont(textstate.f);
textstate.x += k;
textstate.y -= (int)((double)textstate.getAscent(g) * sup_offset + 0.5D);
break;
case 95: // '_'
int l = textstate.getWidth(g);
if(!textstate.isEmpty())
{
textstate = textstate.copyState();
list.addElement(textstate);
}
textstate.f = getScriptFont(textstate.f);
textstate.x += l;
textstate.y += (int)((double)textstate.getDescent(g) * sub_offset + 0.5D);
break;
default:
textstate.s.append(c);
break;
}
}
for(int j1 = 0; j1 < list.size(); j1++)
{
TextState textstate1 = (TextState)list.elementAt(j1);
if(!textstate1.isEmpty())
{
width += textstate1.getWidth(g);
ascent = Math.max(ascent, Math.abs(textstate1.y) + textstate1.getAscent(g));
descent = Math.max(descent, Math.abs(textstate1.y) + textstate1.getDescent(g));
leading = Math.max(leading, textstate1.getLeading(g));
maxDescent = Math.max(maxDescent, Math.abs(textstate1.y) + textstate1.getMaxDescent(g));
maxAscent = Math.max(maxAscent, Math.abs(textstate1.y) + textstate1.getMaxAscent(g));
}
}
height = ascent + descent + leading;
}
public boolean isNull()
{
return text == null;
}
public void draw(Graphics g, int i, int j, int k)
{
justification = k;
if(g == null)
{
return;
} else
{
draw(g, i, j);
return;
}
}
public void draw(Graphics g, int i, int j)
{
int k = i;
int l = j;
if(g == null || text == null)
return;
Graphics g1 = g.create();
parseText(g);
if(justification == 0)
k = i - width / 2;
else
if(justification == 2)
k = i - width;
if(background != null)
{
g1.setColor(background);
g1.fillRect(k, l - ascent, width, height);
g1.setColor(g.getColor());
}
if(font != null)
g1.setFont(font);
if(color != null)
g1.setColor(color);
for(int i1 = 0; i1 < list.size(); i1++)
{
TextState textstate = (TextState)list.elementAt(i1);
if(textstate.f != null)
g1.setFont(textstate.f);
if(textstate.s != null)
g1.drawString(textstate.toString(), textstate.x + k, textstate.y + l);
}
g1.dispose();
g1 = null;
}
public String getFontName()
{
return fontname;
}
public int getFontStyle()
{
return fontstyle;
}
public int getFontSize()
{
return fontsize;
}
public void setFontName(String s)
{
fontname = s;
rebuildFont();
}
public void setFontStyle(int i)
{
fontstyle = i;
rebuildFont();
}
public void setFontSize(int i)
{
fontsize = i;
rebuildFont();
}
private void rebuildFont()
{
parse = true;
if(fontsize <= 0 || fontname == null)
font = null;
else
font = new Font(fontname, fontstyle, fontsize);
}
public Font getScriptFont(Font font1)
{
if(font1 == null)
return font1;
int i = font1.getSize();
if(i <= 6)
return font1;
i = (int)((double)font1.getSize() * script_fraction + 0.5D);
if(i <= 6)
return font1;
else
return new Font(font1.getName(), font1.getStyle(), i);
}
public boolean parseDouble(double d)
{
return parseDouble(d, 7, 6, 2);
}
public boolean parseDouble(double d, int i)
{
return parseDouble(d, i + 1, i, 2);
}
public boolean parseDouble(double d, int i, int j, int k)
{
double d1 = d;
int l = i - j;
double d2 = 0.0D;
StringBuffer stringbuffer = new StringBuffer(i + 4);
if(l < 0)
{
System.out.println("TextLine.parseDouble: Precision > significant figures!");
return false;
}
if(d < 0.0D)
{
d1 = -d;
stringbuffer.append("-");
}
int j1;
if(d == 0.0D)
j1 = 0;
else
j1 = (int)Math.floor(SpecialFunction.log10(d1));
int i1 = j1 - (l - 1);
if(i1 < 0)
{
for(int k1 = i1; k1 < 0; k1++)
d1 *= 10D;
} else
{
for(int l1 = 0; l1 < i1; l1++)
d1 /= 10D;
}
l = (int)d1;
stringbuffer.append(l);
if(j > 0)
{
stringbuffer.append('.');
double d3 = d1 - (double)l;
for(int i2 = 0; i2 < j; i2++)
{
d3 *= 10;
if(i2 == j - 1)
d3 += 0.5D;
stringbuffer.append((int)d3);
d3 -= (int)d3;
}
}
if(i1 != 0)
if(k == 1)
{
stringbuffer.append('E');
if(i1 < 0)
stringbuffer.append('-');
else
stringbuffer.append('+');
i1 = Math.abs(i1);
if(i1 > 9)
{
stringbuffer.append(i1);
} else
{
stringbuffer.append('0');
stringbuffer.append(i1);
}
} else
{
stringbuffer.append("x10{^");
stringbuffer.append(i1);
stringbuffer.append("}");
}
setText(stringbuffer.toString());
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -