Package org.pentaho.reporting.libraries.fonts.registry

Examples of org.pentaho.reporting.libraries.fonts.registry.FontMetrics


    backend = new HashMap();
  }

  public FontMetrics getFontMetrics(final FontKey fontKey)
  {
    final FontMetrics metrics = (FontMetrics) backend.get(fontKey);
    if (metrics != null)
    {
      return metrics;
    }
    if (secondLevelCache == null)
    {
      return null;
    }
    final FontMetrics fromSecondLevel = secondLevelCache.getFontMetrics(fontKey);
    if (fromSecondLevel != null)
    {
      backend.put(fontKey.clone(), fromSecondLevel);
      return fromSecondLevel;
    }
View Full Code Here


                                                    final boolean embedded,
                                                    final boolean antiAliasing) throws IllegalArgumentException
  {
    try
    {
      final FontMetrics metrics = super.getFontMetrics(fontFamily, fontSize, bold, italics, encoding, embedded,
          antiAliasing);
      if (metrics instanceof LegacyFontMetrics)
      {
        final LegacyFontMetrics lm = (LegacyFontMetrics) metrics;
        return (BaseFontFontMetrics) lm.getParent();
View Full Code Here

                      final StyleKey key)
  {
    // Percentages get resolved against the width of a standard space (0x20)
    // character.
    final LayoutStyle layoutContext = currentNode.getLayoutStyle();
    final FontMetrics fm = process.getOutputMetaData().getFontMetrics(layoutContext);
    if (fm == null)
    {
      // we have no font family, so return.
      layoutContext.setValue(TextStyleKeys.X_MIN_LETTER_SPACING, CSSNumericValue.ZERO_LENGTH);
      layoutContext.setValue(TextStyleKeys.X_MAX_LETTER_SPACING, CSSNumericValue.ZERO_LENGTH);
      layoutContext.setValue(TextStyleKeys.X_OPTIMUM_LETTER_SPACING, CSSNumericValue.ZERO_LENGTH);
      return;
    }

    final double width = FontStrictGeomUtility.toExternalValue(fm.getCharWidth(0x20));
    final CSSNumericValue percentageBase =
        CSSNumericValue.createValue(CSSNumericType.PT, width);
    final CSSNumericValue min = StyleSheetUtility.convertLength
        (resolveValue(layoutContext, TextStyleKeys.X_MIN_LETTER_SPACING), percentageBase, currentNode);
    final CSSNumericValue max = StyleSheetUtility.convertLength
View Full Code Here

    {
      return; // no parent to resolve against ...
    }

    final double adjustFactor = nval.getValue();
    final FontMetrics fontMetrics = process.getOutputMetaData().getFontMetrics(layoutContext);
    if (fontMetrics == null)
    {
      return; // no font metrics means no valid font...
    }

    final double actualFontXHeight = FontStrictGeomUtility.toExternalValue(fontMetrics.getXHeight());
    final double fontSize = fontMetrics.getAscent();
    final double aspectRatio = actualFontXHeight / fontSize;
    final double result = (fontSize * (adjustFactor / aspectRatio));

    layoutContext.setValue(FontStyleKeys.FONT_SIZE, CSSNumericValue.createPtValue(result));
  }
View Full Code Here

                      final StyleKey key)
  {
    // Percentages get resolved against the width of a standard space (0x20)
    // character.
    final LayoutStyle layoutContext = currentNode.getLayoutStyle();
    final FontMetrics fm = process.getOutputMetaData().getFontMetrics(layoutContext);
    if (fm == null)
    {
      final CSSValue value = layoutContext.getValue(FontStyleKeys.FONT_FAMILY);
      DebugLog.log ("FontFamily is " + value + " but has not been set?" + currentNode);
      return;
    }
    final double width = FontStrictGeomUtility.toExternalValue(fm.getCharWidth(0x20));
    final CSSNumericValue percentageBase =
            CSSNumericValue.createValue(CSSNumericType.PT, width);
    final CSSNumericValue min = StyleSheetUtility.convertLength
            (resolveValue(layoutContext, TextStyleKeys.X_MIN_WORD_SPACING), percentageBase, currentNode);
    final CSSNumericValue max = StyleSheetUtility.convertLength
View Full Code Here

      final StaticBoxLayoutProperties staticBoxLayoutProperties = writeContext.getStaticBoxLayoutProperties();
      long spaceWidth = staticBoxLayoutProperties.getSpaceWidth();
      if (spaceWidth == 0)
      {
        // Space has not been computed yet.
        final FontMetrics fontMetrics = metaData.getFontMetrics(writeContext.getStyleSheet());
        spaceWidth = StrictGeomUtility.fromFontMetricsValue(fontMetrics.getCharWidth(' '));
        staticBoxLayoutProperties.setSpaceWidth(spaceWidth);
      }

      if (next.isRenderBox())
      {
View Full Code Here

  public void testFontSize()
  {
    final OutputProcessorMetaData metaData = new TextOutputProcessorMetaData
        (12, 12);
    final FontMetrics fontMetrics = metaData.getFontMetrics(ElementDefaultStyleSheet.getDefaultStyle());
    final long charWidth = fontMetrics.getCharWidth('A');
    final long height = fontMetrics.getMaxHeight();
    assertEquals(6000, height);
    assertEquals(6000, charWidth);
  }
View Full Code Here

                                                    final boolean embedded,
                                                    final boolean antiAliasing) throws IllegalArgumentException
  {
    try
    {
      final FontMetrics metrics = super.getFontMetrics(fontFamily, fontSize, bold, italics, encoding, embedded,
          antiAliasing);
      if (metrics instanceof LegacyFontMetrics)
      {
        final LegacyFontMetrics lm = (LegacyFontMetrics) metrics;
        return (BaseFontFontMetrics) lm.getParent();
View Full Code Here

    lookupKey.setFontFamily(fontFamily);
    lookupKey.setFontSize(fontSize);
    lookupKey.setBold(bold);
    lookupKey.setItalics(italics);

    final FontMetrics cached = fontMetricsCache.get(lookupKey);
    if (cached != null)
    {
      return cached;
    }

    final FontRegistry registry = getFontRegistry();
    FontFamily family = registry.getFontFamily(fontFamily);
    if (family == null)
    {
      AbstractOutputProcessorMetaData.logger.warn("Unable to lookup the font family: " + fontFamily);

      // Get the default font name
      final String fallBack = getNormalizedFontFamilyName(null);
      if (fallBack == null)
      {
        // If this case happens, the output-processor meta-data does not provide a sensible
        // fall-back value. As we cannot continue without a font, we fail here instead of
        // waiting for a NullPointer or other weird error later.
        throw new IllegalArgumentException("No default family defined, aborting.");
      }

      family = registry.getFontFamily(fallBack);
      if (family == null)
      {
        // If this case happens, the output-processor meta-data does not provide a sensible
        // fall-back value. As we cannot continue without a font, we fail here instead of
        // waiting for a NullPointer or other weird error later.
        throw new IllegalArgumentException("Default family is invalid. Aborting.");
      }
    }


    reusableFontContext.setAntiAliased(antiAliasing);
    reusableFontContext.setFontSize(fontSize);
    reusableFontContext.setEncoding(encoding);
    reusableFontContext.setEmbedded(embedded);

    final FontRecord record = family.getFontRecord(bold, italics);
    final FontMetrics fm = getFontStorage().getFontMetrics(record.getIdentifier(), reusableFontContext);
    if (fm == null)
    {
      // If this case happens, then the previous steps of mapping the font name into sensible
      // defaults failed. The font-system's font-registry is not in sync with the actual font-metrics
      // provider (which indicates that the LibFonts font-system implementation is invalid).
View Full Code Here

    return fm;
  }

  public ExtendedBaselineInfo getBaselineInfo(final int codePoint, final StyleSheet styleSheet)
  {
    final FontMetrics fontMetrics = getFontMetrics(styleSheet);
    if (fontMetrics.isUniformFontMetrics())
    {
      final String fontFamily = getNormalizedFontFamilyName((String) styleSheet.getStyleProperty(TextStyleKeys.FONT));
      if (fontFamily == null)
      {
        // If this case happens, the stylesheet is not implemented correctly. At that point,
        // we have to assume that the whole engine is no longer behaving valid and therefore we
        // abort early.
        throw new IllegalArgumentException("No valid font family specified.");
      }

      final double fontSize = styleSheet.getDoubleStyleProperty
          (TextStyleKeys.FONTSIZE, defaultFontSize);

      final boolean antiAliasing = RenderUtility.isFontSmooth(styleSheet, this);
      final String encoding = (String) styleSheet.getStyleProperty(TextStyleKeys.FONTENCODING);
      final boolean embedded =
          isFeatureSupported(OutputProcessorFeature.EMBED_ALL_FONTS) ||
              styleSheet.getBooleanStyleProperty(TextStyleKeys.EMBEDDED_FONT);
      final boolean bold = styleSheet.getBooleanStyleProperty(TextStyleKeys.BOLD, false);
      final boolean italics = styleSheet.getBooleanStyleProperty(TextStyleKeys.ITALIC, false);

      lookupKey.setAntiAliased(antiAliasing);
      lookupKey.setEncoding(encoding);
      lookupKey.setEmbedded(embedded);
      lookupKey.setFontFamily(fontFamily);
      lookupKey.setFontSize(fontSize);
      lookupKey.setBold(bold);
      lookupKey.setItalics(italics);

      final ExtendedBaselineInfo cached = baselinesCache.get(lookupKey);
      if (cached != null)
      {
        return cached;
      }
    }
    final ExtendedBaselineInfo baselineInfo = TextUtility.createBaselineInfo('x', fontMetrics, null);
    if (fontMetrics.isUniformFontMetrics())
    {
      baselinesCache.put(new FontMetricsKey(lookupKey), baselineInfo);
    }
    return baselineInfo;
  }
View Full Code Here

TOP

Related Classes of org.pentaho.reporting.libraries.fonts.registry.FontMetrics

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.