Beispiel #1
0
        /// <summary>
        /// Determines whether this instance can draw the specified character.
        /// </summary>
        /// <param name="character">The character.</param>
        /// <param name="drawingBoard">The drawing board.</param>
        /// <param name="columnOffset">The column offset.</param>
        /// <param name="rowOffset">The row offset.</param>
        /// <param name="blender">The blender.</param>
        /// <param name="hasNonBlanks">if set to <c>true</c> [has non spaces].</param>
        /// <returns>
        ///   <c>true</c> if this instance can draw the specified character; otherwise, <c>false</c>.
        /// </returns>
        private bool CanDraw(FIGcharacter character, DrawingBoard drawingBoard, int columnOffset, int rowOffset, IDrawingElementBlender blender, out bool hasNonBlanks)
        {
            hasNonBlanks = false;
            foreach (var element in GetCharacterDrawingElements(character))
            {
                var column = element.Column + columnOffset;
                var row    = element.Row + rowOffset;
                if (column < 0 || row < 0)
                {
                    return(false);
                }
                // this relies on the fact that element.DrawingElement is never null
                var under = drawingBoard[column, row];
                if (blender.TryBlend(under, element.DrawingElement) is null)
                {
                    return(false);
                }
                if (!(under is null) && !under.IsBlank && !element.DrawingElement.IsBlank)
                {
                    hasNonBlanks = true;
                }
            }

            return(true);
        }
Beispiel #2
0
 private void AddCharacter(FIGcharacter character)
 {
     if (!(character is null) && character.Code > 0)
     {
         Characters[character.Code] = character;
     }
 }
Beispiel #3
0
 /// <summary>
 /// Creates a drawing element.
 /// This may be overriden in inherited classes, in order to add your own metadata.
 /// This method is not invoked if a delegate is given to <see cref="FIGdriver"/> constructor.
 /// </summary>
 /// <param name="glyph">The glyph to be displayed.</param>
 /// <param name="character">The related <see cref="FIGcharacter"/> that generated this glyph</param>
 /// <returns></returns>
 protected virtual DrawingElement CreateDrawingElement(char glyph, FIGcharacter character)
 {
     if (glyph == '\0')
     {
         return(null);
     }
     return(new DrawingElement(glyph));
 }
Beispiel #4
0
 private DrawingElement InvokeCreateDrawingElement(FIGcharacter character, char glyph)
 {
     if (!(_createDrawingElement is null))
     {
         return(_createDrawingElement(character, glyph));
     }
     return(CreateDrawingElement(glyph, character));
 }
Beispiel #5
0
 /// <summary>
 /// Draws the specified <see cref="FIGcharacter" /> to <see cref="DrawingBoard" />.
 /// </summary>
 /// <param name="character">The character.</param>
 /// <param name="drawingBoard">The drawing board.</param>
 /// <param name="columnOffset">The column offset.</param>
 /// <param name="rowOffset">The row offset.</param>
 /// <param name="blender">The blender.</param>
 private void Draw(FIGcharacter character, DrawingBoard drawingBoard, int columnOffset, int rowOffset, IDrawingElementBlender blender)
 {
     foreach (var element in GetCharacterDrawingElements(character))
     {
         var column = element.Column + columnOffset;
         var row    = element.Row + rowOffset;
         drawingBoard[column, row] = blender.TryBlend(drawingBoard[column, row], element.DrawingElement) ?? element.DrawingElement;
     }
 }
Beispiel #6
0
 private IEnumerable <CharacterDrawingElement> GetCharacterDrawingElements(FIGcharacter character)
 {
     for (int row = 0; row < character.Height; row++)
     {
         for (int column = 0; column < character.Width; column++)
         {
             var glyph = character[column, row];
             if (glyph == Font.HardBlank)
             {
                 glyph = HardBlank;
             }
             var drawingElement = InvokeCreateDrawingElement(character, glyph);
             if (drawingElement is null)
             {
                 continue;
             }
             yield return(new CharacterDrawingElement(column, row, drawingElement));
         }
     }
 }
Beispiel #7
0
        private int AdjustCaret(FIGcharacter character, DrawingBoard drawingBoard, int columnOffset, int rowOffset, IDrawingElementBlender blender)
        {
            // this is the poor man's fix (again)
            // character does not have a visual, so we ignore it
            if (character.Width == 0)
            {
                return(columnOffset);
            }

            var previousHasNonBlanks = false;

            for (; ; columnOffset--)
            {
                if (!CanDraw(character, drawingBoard, columnOffset - 1, rowOffset, blender, out var hasNonBlanks) || previousHasNonBlanks)
                {
                    return(columnOffset);
                }
                previousHasNonBlanks = hasNonBlanks;
            }
        }