本文整理汇总了Java中java.awt.Font.getStyle方法的典型用法代码示例。如果您正苦于以下问题:Java Font.getStyle方法的具体用法?Java Font.getStyle怎么用?Java Font.getStyle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Font
的用法示例。
在下文中一共展示了Font.getStyle方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStrike
import java.awt.Font; //导入方法依赖的package包/类
public FontStrike getStrike(Font font, FontRenderContext frc) {
AffineTransform at = frc.getTransform();
double ptSize = font.getSize2D();
at.scale(ptSize, ptSize);
if (font.isTransformed()) {
at.concatenate(font.getTransform());
if (at.getTranslateX() != 0 || at.getTranslateY() != 0) {
at.setTransform(at.getScaleX(),
at.getShearY(),
at.getShearX(),
at.getScaleY(),
0.0, 0.0);
}
}
int aa = FontStrikeDesc.getAAHintIntVal(this, font, frc);
int fm = FontStrikeDesc.getFMHintIntVal(frc.getFractionalMetricsHint());
FontStrikeDesc desc = new FontStrikeDesc(frc.getTransform(),
at, font.getStyle(),
aa, fm);
return getStrike(desc, false);
}
示例2: setDefaultChartFonts
import java.awt.Font; //导入方法依赖的package包/类
/**
* Changes the font of {@link JFreeChart}s to Sans Serif. This method uses a
* {@link StandardChartTheme} to do so, so any changes to the look of the chart must be done
* after calling this method.
*
* @param chart
* the chart to change fonts for
*/
protected static void setDefaultChartFonts(JFreeChart chart) {
final ChartTheme chartTheme = StandardChartTheme.createJFreeTheme();
if (StandardChartTheme.class.isAssignableFrom(chartTheme.getClass())) {
StandardChartTheme standardTheme = (StandardChartTheme) chartTheme;
// The default font used by JFreeChart cannot render japanese etc symbols
final Font oldExtraLargeFont = standardTheme.getExtraLargeFont();
final Font oldLargeFont = standardTheme.getLargeFont();
final Font oldRegularFont = standardTheme.getRegularFont();
final Font oldSmallFont = standardTheme.getSmallFont();
final Font extraLargeFont = new Font(Font.SANS_SERIF, oldExtraLargeFont.getStyle(), oldExtraLargeFont.getSize());
final Font largeFont = new Font(Font.SANS_SERIF, oldLargeFont.getStyle(), oldLargeFont.getSize());
final Font regularFont = new Font(Font.SANS_SERIF, oldRegularFont.getStyle(), oldRegularFont.getSize());
final Font smallFont = new Font(Font.SANS_SERIF, oldSmallFont.getStyle(), oldSmallFont.getSize());
standardTheme.setExtraLargeFont(extraLargeFont);
standardTheme.setLargeFont(largeFont);
standardTheme.setRegularFont(regularFont);
standardTheme.setSmallFont(smallFont);
standardTheme.apply(chart);
}
}
示例3: createText
import java.awt.Font; //导入方法依赖的package包/类
public static Element createText(Document doc, Text text) {
Element elt = doc.createElement("text");
Location loc = text.getLocation();
Font font = text.getValue(DrawAttr.FONT);
Color fill = text.getValue(DrawAttr.FILL_COLOR);
Object halign = text.getValue(DrawAttr.ALIGNMENT);
elt.setAttribute("x", "" + loc.getX());
elt.setAttribute("y", "" + loc.getY());
if (!colorMatches(fill, Color.BLACK)) {
elt.setAttribute("fill", getColorString(fill));
}
if (showOpacity(fill)) {
elt.setAttribute("fill-opacity", getOpacityString(fill));
}
elt.setAttribute("font-family", font.getFamily());
elt.setAttribute("font-size", "" + font.getSize());
int style = font.getStyle();
if ((style & Font.ITALIC) != 0) {
elt.setAttribute("font-style", "italic");
}
if ((style & Font.BOLD) != 0) {
elt.setAttribute("font-weight", "bold");
}
if (halign == DrawAttr.ALIGN_LEFT) {
elt.setAttribute("text-anchor", "start");
} else if (halign == DrawAttr.ALIGN_RIGHT) {
elt.setAttribute("text-anchor", "end");
} else {
elt.setAttribute("text-anchor", "middle");
}
elt.appendChild(doc.createTextNode(text.getText()));
return elt;
}
示例4: FontInfo
import java.awt.Font; //导入方法依赖的package包/类
FontInfo(Font origFont, JTextComponent textComponent, FontRenderContext frc, float rowHeightCorrection, int textZoom) {
renderFont = (textZoom != 0)
? new Font(origFont.getName(), origFont.getStyle(), Math.max(origFont.getSize() + textZoom, 1))
: origFont;
char defaultChar = 'A';
String defaultCharText = String.valueOf(defaultChar);
TextLayout defaultCharTextLayout = new TextLayout(defaultCharText, renderFont, frc); // NOI18N
TextLayout rowHeightTextLayout = new TextLayout("A_|B", renderFont, frc);
// Round the ascent to eliminate long mantissa without any visible effect on rendering.
updateRowHeight(rowHeightTextLayout, rowHeightCorrection);
// Ceil fractions to whole numbers since this measure may be used for background rendering
charWidth = (float) Math.ceil(defaultCharTextLayout.getAdvance());
LineMetrics lineMetrics = renderFont.getLineMetrics(defaultCharText, frc);
underlineAndStrike[0] = lineMetrics.getUnderlineOffset() * rowHeightCorrection;
underlineAndStrike[1] = lineMetrics.getUnderlineThickness();
underlineAndStrike[2] = lineMetrics.getStrikethroughOffset() * rowHeightCorrection;
underlineAndStrike[3] = lineMetrics.getStrikethroughThickness();
if (LOG.isLoggable(Level.FINE)) {
FontMetrics fm = textComponent.getFontMetrics(origFont); // From original font
LOG.fine("Orig Font=" + origFont + // NOI18N
"\n " + this + ", charWidth=" + charWidth + ", textZoom=" + textZoom + // NOI18N
"\n rowHeightCorrection=" + rowHeightCorrection + // NOI18N
", underlineO/T=" + underlineAndStrike[0] + "/" + underlineAndStrike[1] + // NOI18N
", strikethroughO/T=" + underlineAndStrike[2] + "/" + underlineAndStrike[3] + // NOI18N
"\n FontMetrics (for comparison; without-RHC): fm-line-height=" + fm.getHeight() + // NOI18N
", fm-ascent,descent,leading=" + fm.getAscent() + "," + fm.getDescent() + "," + fm.getLeading() + // NOI18N
"\n"); // NOI18N
if (LOG.isLoggable(Level.FINEST)) {
LOG.log(Level.FINEST, "FontInfo creation stacktrace", new Exception()); // NOI18N
}
}
}
示例5: getStrike
import java.awt.Font; //导入方法依赖的package包/类
public FontStrike getStrike(Font font, AffineTransform devTx,
int aa, int fm) {
/* Create the descriptor which is used to identify a strike
* in the strike cache/map. A strike is fully described by
* the attributes of this descriptor.
*/
/* REMIND: generating garbage and doing computation here in order
* to include pt size in the tx just for a lookup! Figure out a
* better way.
*/
double ptSize = font.getSize2D();
AffineTransform glyphTx = (AffineTransform)devTx.clone();
glyphTx.scale(ptSize, ptSize);
if (font.isTransformed()) {
glyphTx.concatenate(font.getTransform());
}
if (glyphTx.getTranslateX() != 0 || glyphTx.getTranslateY() != 0) {
glyphTx.setTransform(glyphTx.getScaleX(),
glyphTx.getShearY(),
glyphTx.getShearX(),
glyphTx.getScaleY(),
0.0, 0.0);
}
FontStrikeDesc desc = new FontStrikeDesc(devTx, glyphTx,
font.getStyle(), aa, fm);
return getStrike(desc, false);
}
示例6: sizeLabelFont
import java.awt.Font; //导入方法依赖的package包/类
private void sizeLabelFont(GLabel label, double width, double height) {
int size, style;
String name;
Font f = label.getFont();
name = f.getFontName();
style = f.getStyle();
size = f.getSize();
while(label.getWidth() < width && label.getHeight() < height) {
f = label.getFont();
size = f.getSize();
label.setFont(new Font(name, style, size+1));
}
label.setFont(new Font(name, style, size-1));
}
示例7: changeTickFontSize
import java.awt.Font; //导入方法依赖的package包/类
/**
* Increases or decreases the tick font size.
*
* @param delta the change in size.
*/
public void changeTickFontSize(int delta) {
Font f = getTickLabelFont();
String fName = f.getFontName();
Font newFont = new Font(fName, f.getStyle(), (f.getSize() + delta));
setTickLabelFont(newFont);
}
示例8: CloneFont
import java.awt.Font; //导入方法依赖的package包/类
public static Font CloneFont(Font origem) {
return new Font(origem.getName(), origem.getStyle(), origem.getSize());
}
示例9: getString
import java.awt.Font; //导入方法依赖的package包/类
private String getString(Font value) {
return value.getName() + COMMA + value.getStyle() + COMMA + value.getSize();
}
示例10: textOut
import java.awt.Font; //导入方法依赖的package包/类
private void textOut(String str,
Font font, PhysicalFont font2D,
FontRenderContext frc,
float deviceSize, int rotation, float awScale,
double scaleFactorX, double scaleFactorY,
float userx, float usery,
float devx, float devy, float targetW) {
String family = font2D.getFamilyName(null);
int style = font.getStyle() | font2D.getStyle();
WPrinterJob wPrinterJob = (WPrinterJob)getPrinterJob();
boolean setFont = wPrinterJob.setFont(family, deviceSize, style,
rotation, awScale);
if (!setFont) {
super.drawString(str, userx, usery, font, frc, targetW);
return;
}
float[] glyphPos = null;
if (!okGDIMetrics(str, font, frc, scaleFactorX)) {
/* If there is a 1:1 char->glyph mapping then char positions
* are the same as glyph positions and we can tell GDI
* where to place the glyphs.
* On drawing we remove control chars so these need to be
* removed now so the string and positions are the same length.
* For other cases we need to pass glyph codes to GDI.
*/
str = wPrinterJob.removeControlChars(str);
char[] chars = str.toCharArray();
int len = chars.length;
GlyphVector gv = null;
if (!FontUtilities.isComplexText(chars, 0, len)) {
gv = font.createGlyphVector(frc, str);
}
if (gv == null) {
super.drawString(str, userx, usery, font, frc, targetW);
return;
}
glyphPos = gv.getGlyphPositions(0, len, null);
Point2D gvAdvPt = gv.getGlyphPosition(gv.getNumGlyphs());
/* GDI advances must not include device space rotation.
* See earlier comment in printGlyphVector() for details.
*/
AffineTransform advanceTransform =
AffineTransform.getScaleInstance(scaleFactorX, scaleFactorY);
float[] glyphAdvPos = new float[glyphPos.length];
advanceTransform.transform(glyphPos, 0, //source
glyphAdvPos, 0, //destination
glyphPos.length/2); //num points
glyphPos = glyphAdvPos;
}
wPrinterJob.textOut(str, devx, devy, glyphPos);
}
示例11: lstSizeValueChanged
import java.awt.Font; //导入方法依赖的package包/类
private void lstSizeValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstSizeValueChanged
int size = Integer.parseInt((String)lstSize.getSelectedValue());
font = new Font(font.getFamily(),font.getStyle(),size);
lblPreview.setFont(font);
}
示例12: checkDefaultFontType
import java.awt.Font; //导入方法依赖的package包/类
/**
* Check if the font currently used for standard mode is of the same type as
* font for wrapped mode (default, monospaced).
*/
private boolean checkDefaultFontType() {
Font defFont = getDefaultFont();
return defFont.getName().equals(font.getName())
&& defFont.getStyle() == font.getStyle();
}
示例13: DoPaint
import java.awt.Font; //导入方法依赖的package包/类
@Override
public void DoPaint(Graphics2D g) {
super.DoPaint(g);
Rectangle rec = getArea();
Color bkpc = g.getColor();
g.setColor(getBorderColor());
g.drawRect(rec.x, rec.y, rec.width, rec.height);
Rectangle bkp = g.getClipBounds();
g.clipRect(rec.x, rec.y, rec.width, rec.height);
Font fn = getFont();
Font font = new Font(fn.getFontName(), fn.getStyle(), fn.getSize() - 2);
fn = g.getFont();
g.setFont(font);
altura = g.getFontMetrics().getHeight() + g.getFontMetrics().getDescent();
alturaTitulo = altura + altura / 2;
Composite originalComposite = g.getComposite();
float alfa = 0.8f;
g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alfa));
if (getTipo() == TipoLegenda.tpObjetos) {
altura = Math.max(32, altura);
}
int posi = altura + alturaTitulo + rec.y;
final int lft = rec.x + 2;
for (ItemDeLegenda it : getItens()) {
if (it.isSelecionada()) {
g.setColor(isDisablePainted()? disabledColor : new Color(204, 204, 255, 50));
g.fillRect(lft, posi - altura - 2, getWidth(), altura + 4);
}
g.setColor(isDisablePainted()? disabledColor : it.cor);
int moveleft;
switch (getTipo()) {
case tpLinhas:
moveleft = 3 * altura;
g.fillRoundRect(lft, posi - (altura / 2) - 2, moveleft - 2, 4, 2, 2);
g.setColor(bkpc);
g.drawString(it.texto, lft + moveleft, posi - 6);
break;
case tpObjetos:
ImageIcon img = Editor.fromControler().getImagemNormal(getMaster().getCassesDoDiagrama()[it.getTag()].getSimpleName());
g.drawImage(util.TratadorDeImagens.ReColorBlackImg(img, it.getCor()), lft, posi - altura, null);
moveleft = altura + 2;
g.drawString(it.texto, lft + moveleft, posi - altura / 2 + 6);
break;
default:
moveleft = altura;
g.fillRect(lft, posi - altura, altura - 4, altura - 4);
g.setColor(bkpc);
g.drawRect(lft, posi - altura, altura - 4, altura - 4);
g.drawString(it.texto, lft + moveleft, posi - 6);
}
it.Area = new Point(posi - altura - 2, altura + 4);
posi += altura + 4;
}
g.setComposite(originalComposite);
// g.setColor(Color.LIGHT_GRAY);
// g.drawLine(lft - 1, posi - altura - 2, getLeft() + getWidth() - 1, posi - altura - 2);
g.setClip(bkp);
g.setFont(fn);
}
示例14: sizeListValueChanged
import java.awt.Font; //导入方法依赖的package包/类
private void sizeListValueChanged(ListSelectionEvent e) {
int size = Integer.parseInt((String) sizeList.getSelectedValue());
font = new Font(font.getFamily(), font.getStyle(), size);
previewLabel.setFont(font);
}