当前位置: 首页>>代码示例>>Java>>正文


Java AttributedCharacterIterator.getAttribute方法代码示例

本文整理汇总了Java中java.text.AttributedCharacterIterator.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java AttributedCharacterIterator.getAttribute方法的具体用法?Java AttributedCharacterIterator.getAttribute怎么用?Java AttributedCharacterIterator.getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.text.AttributedCharacterIterator的用法示例。


在下文中一共展示了AttributedCharacterIterator.getAttribute方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFontAtCurrentPos

import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
static Font getFontAtCurrentPos(AttributedCharacterIterator aci) {

        Object value = aci.getAttribute(TextAttribute.FONT);
        if (value != null) {
            return (Font) value;
        }
        if (aci.getAttribute(TextAttribute.FAMILY) != null) {
            return Font.getFont(aci.getAttributes());
        }

        int ch = CodePointIterator.create(aci).next();
        if (ch != CodePointIterator.DONE) {
            FontResolver resolver = FontResolver.getInstance();
            return resolver.getFont(resolver.getFontIndex(ch), aci.getAttributes());
        }
        return null;
    }
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:TextLine.java

示例2: ComponentLine

import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
ComponentLine(AttributedCharacterIterator it, Font defaultFont, Color defaultColor) {
    for (char c = it.first(); c != CharacterIterator.DONE; c = it.next()) {
        Font font = (Font) it.getAttribute(TextAttribute.FONT);
        Color color = (Color) it.getAttribute(TextAttribute.FOREGROUND);
        mySymbols.add(new Symbol(c, createFont(font, defaultFont), createColor(color, defaultColor)));
    }
    checkSpaces(defaultFont, defaultColor);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:ComponentLine.java

示例3: drawText

import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
@Override
public void drawText(AttributedCharacterIterator iterator, IFontTextDrawerEnv env)
		throws IOException, FontFormatException {
	PDPageContentStream contentStream = env.getContentStream();

	contentStream.beginText();

	Matrix textMatrix = new Matrix();
	textMatrix.scale(1, -1);
	contentStream.setTextMatrix(textMatrix);

	StringBuilder sb = new StringBuilder();
	boolean run = true;
	while (run) {

		Font attributeFont = (Font) iterator.getAttribute(TextAttribute.FONT);
		if (attributeFont == null)
			attributeFont = env.getFont();

		Number fontSize = ((Number) iterator.getAttribute(TextAttribute.SIZE));
		if (fontSize != null)
			attributeFont = attributeFont.deriveFont(fontSize.floatValue());
		PDFont font = applyFont(attributeFont, env);

		Paint paint = (Paint) iterator.getAttribute(TextAttribute.FOREGROUND);
		if (paint == null)
			paint = env.getPaint();

		/*
		 * Apply the paint
		 */
		env.applyPaint(paint);

		boolean isStrikeThrough = TextAttribute.STRIKETHROUGH_ON
				.equals(iterator.getAttribute(TextAttribute.STRIKETHROUGH));
		boolean isUnderline = TextAttribute.UNDERLINE_ON.equals(iterator.getAttribute(TextAttribute.UNDERLINE));
		boolean isLigatures = TextAttribute.LIGATURES_ON.equals(iterator.getAttribute(TextAttribute.LIGATURES));

		run = iterateRun(iterator, sb);
		String text = sb.toString();

		/*
		 * If we force the text write we may encounter situations where the font can not
		 * display the characters. PDFBox will throw an exception in this case. We will
		 * just silently ignore the text and not display it instead.
		 */
		try {
			showTextOnStream(env, contentStream, attributeFont, font, isStrikeThrough, isUnderline, isLigatures,
					text);
		} catch (IllegalArgumentException e) {
			if (font instanceof PDType1Font && !font.isEmbedded()) {
				/*
				 * We tried to use a builtin default font, but it does not have the needed
				 * characters. So we use a embedded font as fallback.
				 */
				try {
					if (fallbackFontUnknownEncodings == null)
						fallbackFontUnknownEncodings = findFallbackFont(env);
					if (fallbackFontUnknownEncodings != null) {
						env.getContentStream().setFont(fallbackFontUnknownEncodings, attributeFont.getSize2D());
						showTextOnStream(env, contentStream, attributeFont, fallbackFontUnknownEncodings,
								isStrikeThrough, isUnderline, isLigatures, text);
						e = null;
					}
				} catch (IllegalArgumentException ignored) {
					e = ignored;
				}
			}

			if (e != null)
				System.err.println("PDFBoxGraphics: Can not map text " + text + " with font "
						+ attributeFont.getFontName() + ": " + e.getMessage());
		}
	}
	contentStream.endText();
}
 
开发者ID:rototor,项目名称:pdfbox-graphics2d,代码行数:77,代码来源:PdfBoxGraphics2DFontTextDrawer.java

示例4: advanceToFirstFont

import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
/**
 * When this returns, the ACI's current position will be at the start of the
 * first run which does NOT contain a GraphicAttribute.  If no such run exists
 * the ACI's position will be at the end, and this method will return false.
 */
static boolean advanceToFirstFont(AttributedCharacterIterator aci) {

    for (char ch = aci.first();
         ch != CharacterIterator.DONE;
         ch = aci.setIndex(aci.getRunLimit()))
    {

        if (aci.getAttribute(TextAttribute.CHAR_REPLACEMENT) == null) {
            return true;
        }
    }

    return false;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:TextLine.java

示例5: checkIteratorAttribute

import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
private static final void checkIteratorAttribute(AttributedCharacterIterator iterator, int index, Attribute key, Object expectedValue) throws Exception {
    iterator.setIndex(index);
    Object value = iterator.getAttribute(key);
    if (!((expectedValue == null && value == null) || (expectedValue != null && expectedValue.equals(value)))) {
        throwException(iterator, "iterator returns wrong attribute value - " + value + " instead of " + expectedValue);
    }
    value = iterator.getAttributes().get(key);
    if (!((expectedValue == null && value == null) || (expectedValue != null && expectedValue.equals(value)))) {
        throwException(iterator, "iterator's map returns wrong attribute value - " + value + " instead of " + expectedValue);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:AttributedStringTest.java

示例6: canDrawText

import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
@Override
public boolean canDrawText(AttributedCharacterIterator iterator, IFontTextDrawerEnv env)
		throws IOException, FontFormatException {
	/*
	 * When no font is registered we can not display the text using a font...
	 */
	if (fontMap.size() == 0 && fontFiles.size() == 0 && !hasDynamicFontMapping())
		return false;

	boolean run = true;
	StringBuilder sb = new StringBuilder();
	while (run) {

		Font attributeFont = (Font) iterator.getAttribute(TextAttribute.FONT);
		if (attributeFont == null)
			attributeFont = env.getFont();
		if (mapFont(attributeFont, env) == null)
			return false;

		/*
		 * We can not do a Background on the text currently.
		 */
		if (iterator.getAttribute(TextAttribute.BACKGROUND) != null)
			return false;

		boolean isStrikeThrough = TextAttribute.STRIKETHROUGH_ON
				.equals(iterator.getAttribute(TextAttribute.STRIKETHROUGH));
		boolean isUnderline = TextAttribute.UNDERLINE_ON.equals(iterator.getAttribute(TextAttribute.UNDERLINE));
		boolean isLigatures = TextAttribute.LIGATURES_ON.equals(iterator.getAttribute(TextAttribute.LIGATURES));
		if (isStrikeThrough || isUnderline || isLigatures)
			return false;

		run = iterateRun(iterator, sb);
		String s = sb.toString();
		int l = s.length();
		for (int i = 0; i < l;) {
			int codePoint = s.codePointAt(i);
			switch (Character.getDirectionality(codePoint)) {
			/*
			 * We can handle normal LTR.
			 */
			case Character.DIRECTIONALITY_LEFT_TO_RIGHT:
			case Character.DIRECTIONALITY_EUROPEAN_NUMBER:
			case Character.DIRECTIONALITY_EUROPEAN_NUMBER_SEPARATOR:
			case Character.DIRECTIONALITY_EUROPEAN_NUMBER_TERMINATOR:
			case Character.DIRECTIONALITY_WHITESPACE:
			case Character.DIRECTIONALITY_COMMON_NUMBER_SEPARATOR:
			case Character.DIRECTIONALITY_NONSPACING_MARK:
			case Character.DIRECTIONALITY_BOUNDARY_NEUTRAL:
			case Character.DIRECTIONALITY_PARAGRAPH_SEPARATOR:
			case Character.DIRECTIONALITY_SEGMENT_SEPARATOR:
			case Character.DIRECTIONALITY_OTHER_NEUTRALS:
			case Character.DIRECTIONALITY_ARABIC_NUMBER:
				break;
			case Character.DIRECTIONALITY_RIGHT_TO_LEFT:
			case Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC:
			case Character.DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING:
			case Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE:
			case Character.DIRECTIONALITY_POP_DIRECTIONAL_FORMAT:
				/*
				 * We can not handle this
				 */
				return false;
			default:
				/*
				 * Default: We can not handle this
				 */
				return false;
			}

			if (!attributeFont.canDisplay(codePoint))
				return false;

			i += Character.charCount(codePoint);
		}
	}
	return true;
}
 
开发者ID:rototor,项目名称:pdfbox-graphics2d,代码行数:79,代码来源:PdfBoxGraphics2DFontTextDrawer.java

示例7: main

import java.text.AttributedCharacterIterator; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {

        String text = "Hello world";
        AttributedString as = new AttributedString(text);

        // add non-Annotation attributes
        as.addAttribute(TextAttribute.WEIGHT,
                        TextAttribute.WEIGHT_LIGHT,
                        0,
                        3);
        as.addAttribute(TextAttribute.WEIGHT,
                        TextAttribute.WEIGHT_BOLD,
                        3,
                        5);
        as.addAttribute(TextAttribute.WEIGHT,
                        TextAttribute.WEIGHT_EXTRABOLD,
                        5,
                        text.length());

        // add Annotation attributes
        as.addAttribute(TextAttribute.WIDTH,
                        new Annotation(TextAttribute.WIDTH_EXTENDED),
                        0,
                        3);
        as.addAttribute(TextAttribute.WIDTH,
                        new Annotation(TextAttribute.WIDTH_CONDENSED),
                        3,
                        4);

        AttributedCharacterIterator aci = as.getIterator(null, 2, 4);

        aci.first();
        int runStart = aci.getRunStart();
        if (runStart != 2) {
            throw new Exception("1st run start is wrong. ("+runStart+" should be 2.)");
        }

        int runLimit = aci.getRunLimit();
        if (runLimit != 3) {
            throw new Exception("1st run limit is wrong. ("+runLimit+" should be 3.)");
        }

        Object value = aci.getAttribute(TextAttribute.WEIGHT);
        if (value != TextAttribute.WEIGHT_LIGHT) {
            throw new Exception("1st run attribute is wrong. ("
                                +value+" should be "+TextAttribute.WEIGHT_LIGHT+".)");
        }

        value = aci.getAttribute(TextAttribute.WIDTH);
        if (value != null) {
            throw new Exception("1st run annotation is wrong. ("
                                +value+" should be null.)");
        }

        aci.setIndex(runLimit);
        runStart = aci.getRunStart();
        if (runStart != 3) {
            throw new Exception("2nd run start is wrong. ("+runStart+" should be 3.)");
        }

        runLimit = aci.getRunLimit();
        if (runLimit != 4) {
            throw new Exception("2nd run limit is wrong. ("+runLimit+" should be 4.)");
        }
        value = aci.getAttribute(TextAttribute.WEIGHT);
        if (value != TextAttribute.WEIGHT_BOLD) {
            throw new Exception("2nd run attribute is wrong. ("
                                +value+" should be "+TextAttribute.WEIGHT_BOLD+".)");
        }

        value = aci.getAttribute(TextAttribute.WIDTH);
        if (!(value instanceof Annotation)
            || (((Annotation)value).getValue() !=  TextAttribute.WIDTH_CONDENSED)) {
            throw new Exception("2nd run annotation is wrong. (" + value + " should be "
                                + new Annotation(TextAttribute.WIDTH_CONDENSED)+".)");
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:78,代码来源:getRunStartLimitTest.java


注:本文中的java.text.AttributedCharacterIterator.getAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。