Exemple #1
0
        protected override void Init(UiController controller, object binding, DefinitionFile definition)
        {
            base.Init(controller, binding, definition);

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(Text));

            string font        = DefinitionResolver.GetString(controller, binding, file["Font"]);
            int    fontSize    = DefinitionResolver.Get <int>(controller, binding, file["FontSize"], 0);
            int    fontSpacing = DefinitionResolver.Get <int>(controller, binding, file["FontSpacing"], 0);

            _lineHeight = DefinitionResolver.Get <int>(controller, binding, file["LineHeight"], 100);

            _font = new UiFont(font, fontSize, fontSpacing);

            _textRotation = DefinitionResolver.Get <TextRotation>(controller, binding, file["TextRotation"], TextRotation.None);

            HorizontalContentAlignment horzAlign = DefinitionResolver.Get <HorizontalContentAlignment>(controller, binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Center);
            VerticalContentAlignment   vertAlign = DefinitionResolver.Get <VerticalContentAlignment>(controller, binding, file["VerticalContentAlignment"], VerticalContentAlignment.Center);

            _pathEllipsis = DefinitionResolver.Get <bool>(controller, binding, file["PathEllipsis"], false);

            _line = DefinitionResolver.Get <int>(controller, binding, file["Line"], -1);

            if (_pathEllipsis || _line >= 0)
            {
                _stringBuilder = new StringBuilder();
            }

            _textAlign = UiHelper.TextAlignFromContentAlignment(horzAlign, vertAlign);
            _text      = DefinitionResolver.GetSharedString(controller, binding, file["Text"]);
        }
Exemple #2
0
        public Tick(IStreamReader reader, GraphRecordNumber id, ushort length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            // initialize class members from stream
            this.tktMajor = (MarkLocation)reader.ReadByte();
            this.tktMinor = (MarkLocation)reader.ReadByte();
            this.tlt      = (MarkLabelLocation)reader.ReadByte();
            this.wBkgMode = (BackgroundMode)reader.ReadByte();
            this.rgb      = new RGBColor(reader.ReadInt32(), RGBColor.ByteOrder.RedFirst);
            reader.ReadBytes(16); // rerserved
            ushort flags = reader.ReadUInt16();

            this.fAutoCo       = Utils.BitmaskToBool(flags, 0x1);
            this.fAutoMode     = Utils.BitmaskToBool(flags, 0x2);
            this.rot           = (TextRotation)Utils.BitmaskToInt(flags, 0x1C);
            this.fAutoRot      = Utils.BitmaskToBool(flags, 0x10);
            this.iReadingOrder = (ReadingOrder)Utils.BitmaskToInt(flags, 0xC000);
            this.icv           = reader.ReadUInt16();
            this.trot          = reader.ReadUInt16();

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Exemple #3
0
        protected override bool Init(object controller, object binding, DefinitionFile definition)
        {
            if (!base.Init(controller, binding, definition))
            {
                return(false);
            }

            DefinitionFileWithStyle file = new DefinitionFileWithStyle(definition, typeof(UiLabel));

            string fontName    = file["Font"] as string;
            int    fontSize    = DefinitionResolver.Get <int>(Controller, Binding, file["FontSize"], 0);
            int    fontSpacing = DefinitionResolver.Get <int>(Controller, Binding, file["FontSpacing"], 0);

            _font = new UiFont(fontName, fontSize, fontSpacing);

            _lineHeight = DefinitionResolver.Get <int>(Controller, Binding, file["LineHeight"], 100);

            _textMargin = DefinitionResolver.Get <Margin>(Controller, Binding, file["TextMargin"], Margin.None);

            _rotation = DefinitionResolver.Get <TextRotation>(Controller, Binding, file["TextRotation"], TextRotation.None);

            _maxWidth = DefinitionResolver.Get <Length>(Controller, Binding, file["MaxWidth"], new Length(pixels: int.MaxValue));

            Text = DefinitionResolver.GetSharedString(Controller, Binding, file["Text"]);

            if (Text == null)
            {
                return(false);
            }

            TextColor = DefinitionResolver.GetColorWrapper(Controller, Binding, file["TextColor"]) ?? DefaultTextColor;

            HorizontalContentAlignment horzAlign = DefinitionResolver.Get <HorizontalContentAlignment>(Controller, Binding, file["HorizontalContentAlignment"], HorizontalContentAlignment.Auto);
            VerticalContentAlignment   vertAlign = DefinitionResolver.Get <VerticalContentAlignment>(Controller, Binding, file["VerticalContentAlignment"], VerticalContentAlignment.Auto);

            if (horzAlign == HorizontalContentAlignment.Auto)
            {
                horzAlign = UiHelper.ContentAlignFromAlignment(PositionParameters.HorizontalAlignment);
            }

            if (vertAlign == VerticalContentAlignment.Auto)
            {
                vertAlign = UiHelper.ContentAlignFromAlignment(PositionParameters.VerticalAlignment);
            }

            TextAlign = UiHelper.TextAlignFromContentAlignment(horzAlign, vertAlign);

            if (DefinitionResolver.Get <bool>(Controller, Binding, file["AutoSizeUpdate"], false))
            {
                Text.ValueChanged += Text_ValueChanged;
            }

            return(true);
        }
 public void Draw(PaintArgs p, Font font, Color foreColor, Color backColor)
 {
     if (this.Source != null && this.Visible)
     {
         string           s              = this.Source.Object.ToString();
         Rectangle        bounds         = this.Bounds;
         DrawStringFormat genericDefault = DrawStringFormat.GenericDefault;
         genericDefault.Alignment     = StringAlignment.Center;
         genericDefault.LineAlignment = StringAlignment.Center;
         p.Graphics.FillRectangle(p.Graphics.Brush(backColor), bounds);
         BorderSimple.Draw(p, bounds, BorderStyleSimple.Raised, backColor);
         TextRotation rotation = (this.Destination.Object == null || this.Destination.Object is PlotDataView) ? ((this.DestinationSide != 0) ? ((this.DestinationSide == PlotDragSide.Right) ? TextRotation.X090 : TextRotation.X000) : TextRotation.X270) : ((!this.Destination.Object.DockLeft) ? (this.Destination.Object.DockRight ? TextRotation.X090 : TextRotation.X000) : TextRotation.X270);
         p.Graphics.DrawRotatedText(s, font, foreColor, bounds, rotation, genericDefault);
     }
 }
 public void Draw(PaintArgs p, Font font, Color foreColor, Color backColor)
 {
     if (this.Object != null && this.Visible)
     {
         string           s              = this.Object.ToString();
         Rectangle        rectangle      = (!(this is PlotLayoutBlockGroup)) ? this.BoundsLayout : (this as PlotLayoutBlockGroup).InnerRectangleLayout;
         DrawStringFormat genericDefault = DrawStringFormat.GenericDefault;
         genericDefault.Alignment     = StringAlignment.Center;
         genericDefault.LineAlignment = StringAlignment.Center;
         p.Graphics.FillRectangle(p.Graphics.Brush(this.BackColor), rectangle);
         BorderSimple.Draw(p, rectangle, BorderStyleSimple.Raised, backColor);
         TextRotation rotation = (!(this.Object is PlotDataView)) ? ((!this.Object.DockLeft) ? (this.Object.DockRight ? TextRotation.X090 : TextRotation.X000) : TextRotation.X270) : TextRotation.X000;
         p.Graphics.DrawRotatedText(s, font, foreColor, rectangle, rotation, genericDefault);
     }
 }
        public override int GetHashCode()
        {
            var hashCode = -596887160;

            hashCode = hashCode * -1521134295 + Horizontal.GetHashCode();
            hashCode = hashCode * -1521134295 + Vertical.GetHashCode();
            hashCode = hashCode * -1521134295 + Indent.GetHashCode();
            hashCode = hashCode * -1521134295 + JustifyLastLine.GetHashCode();
            hashCode = hashCode * -1521134295 + ReadingOrder.GetHashCode();
            hashCode = hashCode * -1521134295 + RelativeIndent.GetHashCode();
            hashCode = hashCode * -1521134295 + ShrinkToFit.GetHashCode();
            hashCode = hashCode * -1521134295 + TextRotation.GetHashCode();
            hashCode = hashCode * -1521134295 + WrapText.GetHashCode();
            hashCode = hashCode * -1521134295 + TopToBottom.GetHashCode();
            return(hashCode);
        }
Exemple #7
0
        private double RotationMarkerToDegrees(TextRotation rotation)
        {
            switch (rotation)
            {
            case TextRotation.CounterClockwise:
                return(-90);

            case TextRotation.Clockwise:
                return(90);

            case TextRotation.UpsideDown:
                return(180);

            default:
                return(0);
            }
        }
Exemple #8
0
        public override int GetHashCode()
        {
            unchecked
            {
                int hash = 19;

                hash = hash * 29 + Horizontal.GetHashCode();
                hash = hash * 29 + Vertical.GetHashCode();
                hash = hash * 29 + Wrap.GetHashCode();
                hash = hash * 29 + ReadingOrder.GetHashCode();
                hash = hash * 29 + TextRotation?.GetHashCode() ?? 0;
                hash = hash * 29 + Indent?.GetHashCode() ?? 0;
                hash = hash * 29 + RelativeIndent?.GetHashCode() ?? 0;
                hash = hash * 29 + JustifyLastLine?.GetHashCode() ?? 0;
                hash = hash * 29 + Shrink?.GetHashCode() ?? 0;
                hash = hash * 29 + MergeCell?.GetHashCode() ?? 0;

                return(hash);
            }
        }
Exemple #9
0
        public TxO(IStreamReader reader, GraphRecordNumber id, ushort length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            // initialize class members from stream
            ushort flags = reader.ReadUInt16();

            this.hAlignment = (HorizontalAlignment)Utils.BitmaskToInt(flags, 0xE);
            this.vAlignment = (VerticalAlignment)Utils.BitmaskToInt(flags, 0x70);
            this.rot        = (TextRotation)reader.ReadUInt16();
            reader.ReadBytes(6); // reserved
            this.cchText   = reader.ReadUInt16();
            this.cbRuns    = reader.ReadUInt16();
            this.ifntEmpty = reader.ReadUInt16();
            reader.ReadBytes(2); // reserved

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);
        }
Exemple #10
0
 public RotationEffect(TextRotation rotation, bool caseSensitive)
 {
     this.Rotation      = rotation;
     this.CaseSensitive = caseSensitive;
 }
Exemple #11
0
        void DrawInternal(PrimitiveBatch primitiveBatch, StringProvider text, Vector2 targetPosition, Color[] colors, float opacity, float spacing, float lineHeight, float scale, TextRotation rotation)
        {
            if (primitiveBatch.PrimitiveType != PrimitiveType.TriangleList)
            {
                throw new Exception("PrimitiveBatch has to be started with TriangleList primitive type.");
            }

            Vector2 right = new Vector2(1, 0);
            Vector2 down  = new Vector2(0, 1);

            switch (rotation)
            {
            case TextRotation.Rotate180:
                right = new Vector2(-1, 0);
                down  = new Vector2(0, -1);
                break;

            case TextRotation.Rotate270:
                right = new Vector2(0, 1);
                down  = new Vector2(-1, 0);
                break;

            case TextRotation.Rotate90:
                right = new Vector2(0, -1);
                down  = new Vector2(1, 0);
                break;
            }

            int  count        = text.Length;
            char previousChar = '\0';

            spacing = (float)Height * spacing * scale;

            Vector2 position = targetPosition;

            Color color;

            for (int idx = 0; idx < count; ++idx)
            {
                char  character = text[idx];
                Glyph glyph     = Find(character);

                if (glyph != null)
                {
                    if (previousChar != '\0')
                    {
                        float kerning = (float)glyph.Kerning(previousChar) / 10f;
                        position += right * (kerning * scale + spacing);
                    }

                    previousChar = character;

                    Vector2 pos = position + down * (scale * (glyph.Top - CapLine));

                    color = colors[idx % colors.Length] * opacity;

                    DrawGlyph(primitiveBatch, glyph, ref pos, ref color, scale, ref right, ref down);

                    position += right * (glyph.Width * scale);
                }
                else if (text[idx] == '\n')
                {
                    if (rotation == TextRotation.Rotate270 || rotation == TextRotation.Rotate90)
                    {
                        position.Y = targetPosition.Y;
                    }
                    else
                    {
                        position.X = targetPosition.X;
                    }

                    position    += down * (lineHeight * Height * scale);
                    previousChar = '\0';
                }
            }
        }
Exemple #12
0
        internal void Draw(PrimitiveBatch primitiveBatch, string text, Vector2 position, Color color, float spacing, float lineHeight, float scale, TextRotation rotation = TextRotation.None)
        {
            StringProvider provider = new StringProvider(text);

            _colors[0] = color;
            DrawInternal(primitiveBatch, provider, position, _colors, 1, spacing, lineHeight, scale, rotation);
        }
Exemple #13
0
        internal void Draw(PrimitiveBatch primitiveBatch, StringBuilder text, Vector2 position, Color[] colors, float opacity, float spacing, float lineHeight, float scale, TextRotation rotation = TextRotation.None)
        {
            StringProvider provider = new StringProvider(text);

            DrawInternal(primitiveBatch, provider, position, colors, opacity, spacing, lineHeight, scale, rotation);
        }
 public Vector2 DrawText(UniversalFont font, SharedString text, Rectangle target, TextAlign align, Color color, float spacing, float lineHeight, float scale, TextRotation rotation = TextRotation.None)
 {
     lock (text)
     {
         return(DrawText(font, text.StringBuilder, target, align, color, spacing, lineHeight, scale, rotation));
     }
 }
 public Vector2 DrawText(UniversalFont font, SharedString text, Rectangle target, TextAlign align, Color color, TextRotation rotation = TextRotation.None)
 {
     return(DrawText(font, text, target, align, color, 0, 0, 1));
 }
        public Vector2 DrawText(UniversalFont font, string text, Rectangle target, TextAlign align, Color color, float spacing, float lineHeight, float scale, TextRotation rotation = TextRotation.None)
        {
            if (font == null || text == null)
            {
                return(Vector2.Zero);
            }

            Font = font;

            Vector2 position;
            Vector2 size;

            size = _font.MeasureString(text, spacing, lineHeight) * scale;

            if (align != TextAlign.None)
            {
                position = TextPosition(ref target, align, size, rotation);
            }
            else
            {
                position = target.Location.ToVector2();
            }

            if (_font.SitanaFont != null)
            {
                PrimitiveType = PrimitiveType.TriangleList;

                PrimitiveBatchNeeded();
                _font.SitanaFont.Draw(_primitiveBatch, text, position, color, spacing, lineHeight, scale, rotation);
            }
            else
            {
                Vector2 origin = Vector2.Zero;

                if (align != TextAlign.None)
                {
                    origin = TextOrigin(align, size);
                }

                position.X += origin.X * scale;

                SpriteBatchIsNeeded();
                _spriteBatch.DrawString(_font.SpriteFont, text, position, color, 0, origin, scale, SpriteEffects.None, 0);
            }

            return(size);
        }
Exemple #17
0
        private Vector2 TextPosition(ref Rectangle target, TextAlign align, Vector2 size, TextRotation rotation)
        {
            if (rotation == TextRotation.Rotate270 || rotation == TextRotation.Rotate90)
            {
                size = new Vector2(size.Y, size.X);
            }

            Vector2 pos = target.Location.ToVector2();

            switch (align & TextAlign.Horz)
            {
            case TextAlign.Right:
                pos.X = target.Right - (int)size.X;
                break;

            case TextAlign.Center:
                pos.X = target.Center.X - (int)size.X / 2;
                break;
            }

            switch (align & TextAlign.Vert)
            {
            case TextAlign.Bottom:
                pos.Y = target.Bottom - (int)size.Y;
                break;

            case TextAlign.Middle:
                pos.Y = target.Center.Y - (int)size.Y / 2;
                break;
            }

            switch (rotation)
            {
            case TextRotation.Rotate90:
                pos.Y += size.Y;
                break;

            case TextRotation.Rotate270:
                pos.X += size.X;
                break;

            case TextRotation.Rotate180:
                pos.X += size.X;
                pos.Y += size.Y;
                break;
            }

            return(pos);
        }
Exemple #18
0
 public RotationEffect(TextRotation rotation) : base()
 {
     this.Rotation      = rotation;
     this.CaseSensitive = true;
 }
Exemple #19
0
        private XRect MakeXRectForRotation(double x, double y, double width, double height, TextRotation rotation)
        {
            double _x = x;
            double _y = y;

            double _width  = width;
            double _height = height;

            if (rotation == TextRotation.Clockwise || rotation == TextRotation.CounterClockwise)
            {
                _width  = height;
                _height = width;
            }


            XRect output = new XRect(_x, _y, _width, _height);

            return(output);
        }
Exemple #20
0
        // draws a single Paper Wallet in to a PdfSharp XForm
        private PdfSharp.Drawing.XForm getSingleWallet(PdfDocument doc, WalletBundle b, XImage imgArtwork, string address, string privkey, int numberWithinBatch, bool layoutDebugging)
        {
            WalletTemplate t = b.template;

            double width  = t.widthMM;
            double height = t.heightMM;

            XUnit walletSizeWide = XUnit.FromMillimeter(width);
            XUnit walletSizeHigh = XUnit.FromMillimeter(height);

            PdfSharp.Drawing.XForm form = new PdfSharp.Drawing.XForm(doc, walletSizeWide, walletSizeHigh);


            using (XGraphics formGfx = XGraphics.FromForm(form))
            {
                XGraphicsState state = formGfx.Save();

                bool interpolateArtwork = true;
                bool interpolateQRcodes = false;

                // XImage imgArtwork is now provided by caller, so this process only has to be done ONCE - because the artwork does not change between Wallets in a run!
                //XImage imgArtwork = XImage.FromGdiPlusImage(b.getArtworkImage());
                imgArtwork.Interpolate = interpolateArtwork;

                formGfx.DrawImage(imgArtwork, new RectangleF(0f, 0f, (float)walletSizeWide.Point, (float)walletSizeHigh.Point));

                // draw the QR codes and legible-text things

                // Address
                // QR
                Bitmap bmpAddress = BtcAddress.QR.EncodeQRCode(address);
                XImage imgAddress = XImage.FromGdiPlusImage(bmpAddress);
                imgAddress.Interpolate = interpolateQRcodes;

                XUnit addressQrLeft = XUnit.FromMillimeter(t.addressQrLeftMM);
                XUnit addressQrTop  = XUnit.FromMillimeter(t.addressQrTopMM);
                XUnit addressQrSize = XUnit.FromMillimeter(t.addressQrSizeMM);

                // only print Address QR if called for
                if (t.addressQrSizeMM > 0.1)
                {
                    XRect addressQrRect = new XRect(addressQrLeft.Point, addressQrTop.Point, addressQrSize.Point, addressQrSize.Point);
                    formGfx.DrawImage(imgAddress, addressQrRect);
                }

                // text address
                string         addressSplitForLines = addressOrReferencePrep(address, t.addressTextCharsPerLine, t.addressTextContentVariant, numberWithinBatch);
                XFont          fontAddress          = new XFont(t.addressTextFontName, t.addressTextFontSize, t.addressTextFontStyle);
                XTextFormatter tf = new XTextFormatter(formGfx);

                XUnit addressTxtLeft   = XUnit.FromMillimeter(t.addressTextLeftMM);
                XUnit addressTxtTop    = XUnit.FromMillimeter(t.addressTextTopMM);
                XUnit addressTxtWidth  = XUnit.FromMillimeter(t.addressTextWidthMM);
                XUnit addressTxtHeight = XUnit.FromMillimeter(t.addressTextHeightMM);

                XRect addressRect = new XRect(addressTxtLeft.Point, addressTxtTop.Point, addressTxtWidth.Point, addressTxtHeight.Point);
                tf.Alignment = XParagraphAlignment.Center;

                TextRotation addressTxtRotation        = t.addressTextRotation;
                double       addressTxtRotationDegrees = RotationMarkerToDegrees(addressTxtRotation);

                if (layoutDebugging)
                {
                    formGfx.DrawRectangle(XBrushes.PowderBlue, addressRect);
                }

                XPoint rotateCentre      = new XPoint(addressTxtLeft + (addressTxtWidth / 2), addressTxtTop + (addressTxtHeight / 2));
                XPoint matrixRotatePoint = new XPoint(addressRect.X + (addressRect.Width / 2), addressRect.Y + (addressRect.Height / 2));

                XMatrix rotateMatrix = new XMatrix();
                rotateMatrix.RotateAtAppend(addressTxtRotationDegrees, rotateCentre);
                addressRect.Transform(rotateMatrix);

                if (layoutDebugging)
                {
                    // draw a little tracer dot for where the centre of rotation is going to be
                    double rotateDotSize = 2.0;
                    formGfx.DrawEllipse(XBrushes.Red, rotateCentre.X - (rotateDotSize / 2), rotateCentre.Y - (rotateDotSize / 2), rotateDotSize, rotateDotSize);
                }

                // maybe even do some rotation of the lovely text!
                formGfx.Save();

                formGfx.RotateAtTransform(addressTxtRotationDegrees, rotateCentre);
                if (layoutDebugging)
                {
                    formGfx.DrawRectangle(XPens.OrangeRed, addressRect);
                }

                if (t.addressTextWidthMM > 0.1)
                {
                    tf.DrawString(addressSplitForLines, fontAddress, t.GetBrushAddress, addressRect);
                }
                formGfx.Restore();

                // Privkey
                // QR
                Bitmap bmpPrivkey = BtcAddress.QR.EncodeQRCode(privkey);
                XImage imgPrivkey = XImage.FromGdiPlusImage(bmpPrivkey);
                imgPrivkey.Interpolate = interpolateQRcodes;

                XUnit privkeyQrLeft = XUnit.FromMillimeter(t.privkeyQrLeftMM);
                XUnit privkeyQrTop  = XUnit.FromMillimeter(t.privkeyQrTopMM);
                XUnit privkeyQrSize = XUnit.FromMillimeter(t.privkeyQrSizeMM);

                XRect privkeyQrRect = new XRect(privkeyQrLeft.Point, privkeyQrTop.Point, privkeyQrSize.Point, privkeyQrSize.Point);

                // only print privkey QR if specified - but you'd have to be an UTTER IDIOT to want to exclude this. Still, user input comes first!
                if (t.privkeyQrSizeMM > 0.1)
                {
                    formGfx.DrawImage(imgPrivkey, privkeyQrRect);
                }

                // legible
                string privkeySplitForLines = lineSplitter(privkey, t.privkeyTextCharsPerLine);

                XFont fontPrivkey = new XFont(t.privkeyTextFontName, t.privkeyTextFontSize, t.privkeyTextFontStyle);

                XUnit privkeyTxtLeft   = XUnit.FromMillimeter(t.privkeyTextLeftMM);
                XUnit privkeyTxtTop    = XUnit.FromMillimeter(t.privkeyTextTopMM);
                XUnit privkeyTxtWidth  = XUnit.FromMillimeter(t.privkeyTextWidthMM);
                XUnit privkeyTxtHeight = XUnit.FromMillimeter(t.privkeyTextHeightMM);

                TextRotation privkeyTxtRotation        = t.privkeyTextRotation;
                double       privkeyTxtRotationDegrees = RotationMarkerToDegrees(privkeyTxtRotation);

                XRect privkeyRect = new XRect(privkeyTxtLeft.Point, privkeyTxtTop.Point, privkeyTxtWidth.Point, privkeyTxtHeight.Point);

                if (layoutDebugging)
                {
                    // draw a tracer rectangle for the original un-rotated text rectangle
                    formGfx.DrawRectangle(XBrushes.PowderBlue, privkeyRect);
                }

                // rotate that lovely text around its middle when drawing!
                rotateCentre = new XPoint(privkeyTxtLeft + (privkeyTxtWidth / 2), privkeyTxtTop + (privkeyTxtHeight / 2));

                matrixRotatePoint = new XPoint(privkeyRect.X + (privkeyRect.Width / 2), privkeyRect.Y + (privkeyRect.Height / 2));

                rotateMatrix = new XMatrix();
                rotateMatrix.RotateAtAppend(privkeyTxtRotationDegrees, rotateCentre);
                privkeyRect.Transform(rotateMatrix);

                if (layoutDebugging)
                {
                    // draw a little tracer dot for where the centre of rotation is going to be
                    double rotateDotSize = 2.0;
                    formGfx.DrawEllipse(XBrushes.Red, rotateCentre.X - (rotateDotSize / 2), rotateCentre.Y - (rotateDotSize / 2), rotateDotSize, rotateDotSize);
                }

                formGfx.Save();

                formGfx.RotateAtTransform(privkeyTxtRotationDegrees, rotateCentre);

                if (layoutDebugging)
                {
                    formGfx.DrawRectangle(XPens.OrangeRed, privkeyRect);
                }

                // only print privkey text if specified.
                if (t.privkeyTextWidthMM > 0.1)
                {
                    tf.DrawString(privkeySplitForLines, fontPrivkey, t.GetBrushPrivkey, privkeyRect);
                }

                formGfx.Restore();
            }



            return(form);
        }
Exemple #21
0
        public TxO(IStreamReader reader, RecordType id, UInt16 length)
            : base(reader, id, length)
        {
            // assert that the correct record type is instantiated
            Debug.Assert(this.Id == ID);

            long startPosition = this.Reader.BaseStream.Position;

            // NOTE: controlInfo is an option field that exists if and only if the value of
            //   cmo.ot in the preceding Obj record is 0, 5, 7, 11, 12 or 14.
            //   However, the current parser implementation does not allow us to see the preceding
            //   record(s) witout an enormous recactoring. Therefore we're a little bit hacky here
            //   and try to read the record first without the optional field. If we didn't succeed
            //   we start a second try, this time including the optional field.
            //
            for (int noOfTries = 1; noOfTries < 3; noOfTries++)
            {
                // initialize class members from stream
                UInt16 flags = reader.ReadUInt16();
                this.hAlignment = (HorizontalAlignment)Utils.BitmaskToInt(flags, 0xE);
                this.vAlignment = (VerticalAlignment)Utils.BitmaskToInt(flags, 0x70);
                this.rot        = (TextRotation)reader.ReadUInt16();
                reader.ReadBytes(6); // reserved

                // read optional field controlInfo on second try
                if (noOfTries == 2)
                {
                    this.controlInfo = new ControlInfo(reader);
                }

                this.cchText   = reader.ReadUInt16();
                this.cbRuns    = reader.ReadUInt16();
                this.ifntEmpty = reader.ReadUInt16();
                this.fmla      = new ObjFmla(reader);

                if (this.Offset + this.Length == this.Reader.BaseStream.Position)
                {
                    break;
                }
                else if (noOfTries == 1)
                {
                    // re-read record, this time including the optional controlInfo field
                    this.Reader.BaseStream.Position = startPosition;
                }
            }

            // assert that the correct number of bytes has been read from the stream
            Debug.Assert(this.Offset + this.Length == this.Reader.BaseStream.Position);

            // NOTE: If the field cchText is not zero, this record doesn‘t fully specify the text.
            //  The rest of the data that MUST be specified is the text string and the formatting runs
            //  information.
            //
            if (this.cchText > 0 && BiffRecord.GetNextRecordType(reader) == RecordType.Continue)
            {
                // skip record header
                reader.ReadUInt16();
                reader.ReadUInt16();

                this.text = new XLUnicodeStringNoCch(reader, this.cchText);
                if (BiffRecord.GetNextRecordType(reader) == RecordType.Continue)
                {
                    // skip record header
                    reader.ReadUInt16();
                    reader.ReadUInt16();

                    this.runs = new TxORuns(reader, this.cbRuns);
                }
            }
        }
Exemple #22
0
        public void DrawRotatedText(string s, Font font, Color foreColor, Rectangle r, TextRotation rotation, DrawStringFormat format)
        {
            if (font != null)
            {
                PointF pointF;
                switch (rotation)
                {
                case TextRotation.X000:
                    this.DrawString(s, font, this.Brush(foreColor), r, format);
                    break;

                case TextRotation.X090:
                {
                    r      = new Rectangle(r.Left, r.Top, r.Height, r.Width);
                    pointF = new PointF((float)(r.Left + r.Height / 2), (float)((r.Top + r.Bottom) / 2));
                    GraphicsState gstate = this.Save();
                    this.TranslateTransform(pointF.X, pointF.Y);
                    this.RotateTransform(90f);
                    this.TranslateTransform(0f - pointF.X, 0f - pointF.Y);
                    this.DrawString(s, font, this.Brush(foreColor), r, format);
                    this.Restore(gstate);
                    break;
                }

                case TextRotation.X180:
                {
                    pointF = new PointF((float)((r.Left + r.Right) / 2), (float)((r.Top + r.Bottom) / 2));
                    GraphicsState gstate = this.Save();
                    this.TranslateTransform(pointF.X, pointF.Y);
                    this.RotateTransform(180f);
                    this.TranslateTransform(0f - pointF.X, 0f - pointF.Y);
                    this.DrawString(s, font, this.Brush(foreColor), r, format);
                    this.Restore(gstate);
                    break;
                }

                case TextRotation.X270:
                {
                    r      = new Rectangle(r.Left, r.Top, r.Height, r.Width);
                    pointF = new PointF((float)((r.Left + r.Right) / 2), (float)(r.Top + r.Width / 2));
                    GraphicsState gstate = this.Save();
                    this.TranslateTransform(pointF.X, pointF.Y);
                    this.RotateTransform(270f);
                    this.TranslateTransform(0f - pointF.X, 0f - pointF.Y);
                    this.DrawString(s, font, this.Brush(foreColor), r, format);
                    this.Restore(gstate);
                    break;
                }
                }
            }
        }