Class FormattedTextEncoder


  • public class FormattedTextEncoder
    extends Object
    Class for encoding/decoding font and color into/from strings which are used in editors and viewers of formatted text.
    • Constructor Detail

      • FormattedTextEncoder

        public FormattedTextEncoder​(IV8Project v8Project,
                                    IMdObjectByTypeProvider objectByTypeProvider,
                                    IColorProvider colorProvider,
                                    IFontProvider fontProvider)
        Creates new encoder instance.
        Parameters:
        v8Project - V8 project, cannot be null
        objectByTypeProvider - object by type provider, cannot be null
        colorProvider - the color provider, cannot be null
        fontProvider - the font provider, cannot be null
    • Method Detail

      • getDefaultFont

        public Font getDefaultFont()
        Returns default font which can be used if no other fonts specified. For now it is used when user changes font size, but does not specify font family.
        Returns:
        the default font, cannot be null
      • isDefaultFont

        public boolean isDefaultFont​(Font font)
        Returns whether given font is a special default font.
        Parameters:
        font - the font to check
        Returns:
        true if font is a default font, false otherwise
        See Also:
        also#getDefaultFont()
      • getStyledFont

        public Font getStyledFont​(int encodedCompositeId)
        Returns styled font by given compositeId.
        Parameters:
        encodedCompositeId - the encoded composite Id for which to get the font
        Returns:
        the font found or null
      • encodeFont

        public String encodeFont​(Font font)
        Creates encoded face name from font.
        Parameters:
        font - the font to encode
        Returns:
        the encoded face name
      • encodeFontParameters

        public static String encodeFontParameters​(String faceName,
                                                  int size,
                                                  String encodedCompositeId)
        Creates encoded font face name from given font parameters.
        Parameters:
        faceName - font face
        size - font size in points
        encodedCompositeId - encoded composite Id
        Returns:
        the encoded face name
      • encodeCompositeId

        public String encodeCompositeId​(CompositeId compositeId)
        Creates encoded composite Id.
        Parameters:
        compositeId - composite Id to encode
        Returns:
        the encoded value
      • decodeFont

        public Font decodeFont​(String encodedFaceName)
        Creates decoded font from encoded face name.
        Parameters:
        encodedFaceName - face name to decode
        Returns:
        the decoded font instance
      • getStyledColor

        public PlatformColor getStyledColor​(int encodedCompositeId)
        Returns styled color by given compositeId.
        Parameters:
        encodedCompositeId - the compositeId for which to get the color
        Returns:
        the color found or null
      • getStyledColorCompositeId

        public CompositeId getStyledColorCompositeId​(Color color)
        Returns color's composite Id if it is a styled color.
        Parameters:
        color - the color to check
        Returns:
        composite Id or null if color is not a styled color
      • isStyledColor

        public boolean isStyledColor​(Color color)
        Tells whether specified color is a styled one.
        Parameters:
        color - the color to check
        Returns:
        true if given color is a styled color, false otherwise
      • encodeColor

        public String encodeColor​(Color color)
        Creates encoded color name from color.
        Parameters:
        color -
        Returns:
        the color name encoded
      • encodeRgbColor

        public static String encodeRgbColor​(Color color)
        Creates encoded color name from rgb color definition.
        Parameters:
        color - , can be null
        Returns:
        the color name encoded, never null
      • decodeColor

        public Color decodeColor​(String encodedColorName,
                                 String encodedCompositeId)
        Creates decoded color from encoded color name and composite Id string.
        Parameters:
        encodedColorName - encoded color name
        compositeId - encoded composite Id if exists or null
        Returns:
        the decoded color instance
      • encodePicture

        public String encodePicture​(Picture picture)
        Encodes picture into a string.
        Parameters:
        picture - the picture to encode
        Returns:
        the encoded string
      • encodePictureCompositeId

        public String encodePictureCompositeId​(Picture picture)
        Encodes composite Id of the given picture into a string.
        Parameters:
        picture - the picture for which to encode composite Id
        Returns:
        the encoded string or null if composite Id is not found
      • decodePicture

        public Picture decodePicture​(String encodedCompositeId)
        Decodes picture from given encoded composite Id string.
        Parameters:
        compositeId - the encoded composite Id string for which to get the picture
        Returns:
        the picture found or null
      • reloadKnownPictures

        public void reloadKnownPictures​(IV8Project v8Project,
                                        IMdObjectByTypeProvider objectByTypeProvider)
        Reloads the list of known pictures.
        Parameters:
        v8project - V8 project, cannot be null
        objectByTypeProvider - object by type provider, cannot be null