Exemplo n.º 1
0
        private void CopyBackgroundImage(Style target, CellStyle source)
        {
            if (source.BackgroundImage == null || source.BackgroundImageLayout == ImageAlignEnum.Hide)
            {
                return;
            }

            ImageAlignInfo iai = s_ImageAlignToIA[source.BackgroundImageLayout];
            bool           stretch, keepaspect, tile;

            switch (source.BackgroundImageLayout)
            {
            case ImageAlignEnum.Scale:
                stretch    = true;
                keepaspect = true;
                tile       = false;
                break;

            case ImageAlignEnum.Stretch:
                stretch    = true;
                keepaspect = false;
                tile       = false;
                break;

            case ImageAlignEnum.Tile:
                stretch    = false;
                keepaspect = true;
                tile       = true;
                break;

            case ImageAlignEnum.TileStretch:
                // todo: this is a bad workaround:
                stretch    = true;
                keepaspect = false;
                tile       = false;
                break;

            default:
                stretch    = false;
                keepaspect = true;
                tile       = false;
                break;
            }
            target.BackgroundImageAlign = new ImageAlign(iai.Horz, iai.Vert, stretch, stretch, keepaspect, tile, tile);
            if (source.BackgroundImageLayout != ImageAlignEnum.TileStretch)
            {
                target.BackgroundImage = source.BackgroundImage;
            }
            else
            {
                target.BackgroundImage = MakeTileStretchImage(source.BackgroundImage);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adjusts the passed style to mach the appearance of the specified C1FlexGrid cell style.
        /// Also takes into account cell data (affects "general" text alignment), and whether the
        /// cell is at the edge of the containing table (affects borders).
        /// </summary>
        /// <param name="target">The target style to modify.</param>
        /// <param name="source">The source cell style.</param>
        /// <param name="dataType">The grid cell data type (used to disambiguate general text alignment).</param>
        /// <param name="value">The grid cell text (used to disambiguate general text alignment).</param>
        /// <param name="edges">Outer edges of the table on which the cell borders.</param>
        /// <param name="borderLeft">The left border of the cell (which is the right border of the cell on the left).</param>
        /// <param name="borderTop">The top border of the cell (which is the bottom border of the cell on the top).</param>
        private void CopyCellStyle(Style target, CellStyle source, Type dataType, string value, EdgeEnum edges, LineDef borderLeft, LineDef borderTop)
        {
            target.Font      = source.Font;
            target.BackColor = source.BackColor;
            target.TextColor = source.ForeColor;

            if (source.TextDirection == TextDirectionEnum.Up)
            {
                target.TextAngle = 90;
            }
            else if (source.TextDirection == TextDirectionEnum.Down)
            {
                target.TextAngle = 270;
            }

            // source.Trimming

            target.WordWrap = source.WordWrap;
            TextAlignInfo ta = s_TextAlignToTA[GetTextAlign(source, dataType, value)];

            target.TextAlignHorz = ta.Horz;
            target.TextAlignVert = ta.Vert;

            ImageAlignInfo ia = s_ImageAlignToIA[source.ImageAlign];

            target.ImageAlign.AlignHorz = ia.Horz;
            target.ImageAlign.AlignVert = ia.Vert;
            if (source.ImageAlign == ImageAlignEnum.Scale)
            {
                target.ImageAlign.BestFit         = true;
                target.ImageAlign.StretchVert     = true;
                target.ImageAlign.StretchHorz     = true;
                target.ImageAlign.KeepAspectRatio = true;
            }
            else if (source.ImageAlign == ImageAlignEnum.Stretch)
            {
                target.ImageAlign.StretchVert     = true;
                target.ImageAlign.StretchHorz     = true;
                target.ImageAlign.KeepAspectRatio = false;
            }
            else
            {
                target.ImageAlign.StretchVert     = false;
                target.ImageAlign.StretchHorz     = false;
                target.ImageAlign.KeepAspectRatio = true;
            }
            // todo: handle Tile/TileStretch

            // borders:
            if (PrintInfo.PrintBorders)
            {
                // note: outer borders are defined by EmptyArea style.
                // left:
                if ((edges & EdgeEnum.Left) != 0)
                {
                    target.Borders.Left = BorderToLineDef(_grid.Styles.EmptyArea, false);
                }
                else
                {
                    target.Borders.Left = borderLeft;
                }
                // top:
                if ((edges & EdgeEnum.Top) != 0)
                {
                    target.Borders.Top = BorderToLineDef(_grid.Styles.EmptyArea, true);
                }
                else
                {
                    target.Borders.Top = borderTop;
                }
                // right:
                if ((edges & EdgeEnum.Right) != 0)
                {
                    target.Borders.Right = BorderToLineDef(_grid.Styles.EmptyArea, false);
                }
                else
                {
                    target.Borders.Right = BorderToLineDef(source, false);
                }
                // bottom:
                if ((edges & EdgeEnum.Bottom) != 0)
                {
                    target.Borders.Bottom = BorderToLineDef(_grid.Styles.EmptyArea, true);
                }
                else
                {
                    target.Borders.Bottom = BorderToLineDef(source, true);
                }
            }

            CopyBackgroundImage(target, source);

            // style attributes that are ignored (todo):
            // source.TextEffect

            // style attributes that are accounted for elsewhere and/or irrelevant for print:
            // source.Padding
            // source.Display
            // source.Format
            // source.DataType
            // source.ImageAlign
            // source.ImageSpacing
            // source.EditMask
            // source.ComboList
        }