Пример #1
0
        private CircleSegment FindSegment(PointF mpt)
        {
            Point   imPt   = GetImageRelativeLocation(mpt);
            ExtSize imSize = GetImageSize();
            float   dX     = (imPt.X - imSize.Width / 2.0f) / fZoom;
            float   dY     = (imPt.Y - imSize.Height / 2.0f) / fZoom;

            return(fModel.FindSegment(dX, dY));
        }
Пример #2
0
        public void Test_ExtSize()
        {
            ExtSize sz = new ExtSize(9, 9);

            Assert.AreEqual(9, sz.Width);
            Assert.AreEqual(9, sz.Height);
            Assert.IsFalse(sz.IsEmpty);
            Assert.AreEqual("{Width=9, Height=9}", sz.ToString());
        }
Пример #3
0
        /// <summary>
        /// 设置图象
        /// </summary>
        protected void SetBitmap(Bitmap bitmap, byte opacity = 255)
        {
            if (bitmap.PixelFormat != PixelFormat.Format32bppArgb)
            {
                throw new ApplicationException("The bitmap must be 32bpp with alpha-channel.");
            }

            this.ClientSize = new Size(bitmap.Width, bitmap.Height);
            // The idea of this is very simple,
            // 1. Create a compatible DC with screen;
            // 2. Select the bitmap with 32bpp with alpha-channel in the compatible DC;
            // 3. Call the UpdateLayeredWindow.

            IntPtr screenDc  = GetDC(IntPtr.Zero);
            IntPtr memDc     = CreateCompatibleDC(screenDc);
            IntPtr hBitmap   = IntPtr.Zero;
            IntPtr oldBitmap = IntPtr.Zero;

            try
            {
                hBitmap   = bitmap.GetHbitmap(Color.FromArgb(0)); // Grab a GDI handle from this GDI+ bitmap
                oldBitmap = SelectObject(memDc, hBitmap);
                ExtSize          size        = new ExtSize(bitmap.Width, bitmap.Height);
                ExtPoint         pointSource = new ExtPoint(0, 0);
                ExtPoint         topPos      = new ExtPoint(this.Left, this.Top);
                ExtBlendFunction blend       = new ExtBlendFunction
                {
                    BlendOp             = AC_SRC_OVER,
                    BlendFlags          = 0,
                    SourceConstantAlpha = opacity,
                    AlphaFormat         = AC_SRC_ALPHA
                };
                UpdateLayeredWindow(Handle, screenDc, ref topPos, ref size, memDc, ref pointSource, 0, ref blend, ULW_ALPHA);
            }
            finally
            {
                ReleaseDC(IntPtr.Zero, screenDc);

                if (hBitmap != IntPtr.Zero)
                {
                    SelectObject(memDc, oldBitmap);

                    // The documentation says that we have to use the Windows.DeleteObject...
                    // but since there is no such method I use the normal DeleteObject from Win32 GDI
                    // and it's working fine without any resource leak.
                    //
                    // Windows.DeleteObject(hBitmap);
                    DeleteObject(hBitmap);
                }
                DeleteDC(memDc);
            }
            bitmap.Dispose();
        }
Пример #4
0
        /// <summary>
        ///   Recalculates appropriate values for scrollbar bounds.
        /// </summary>
        private void Recalculate()
        {
            fDataRange = GetDataBounds();
            float distance = fDataRange.End - fDataRange.Start;

            fImageSize = new ExtSize((int)(distance * fRenderingScale),
                                     (int)(fPlayheadExtents.Height + (fTracks.Count * (TrackHeight + TrackSpacing)) * fRenderingScale));
            AdjustViewport(fImageSize);

            // Generate colors for the tracks.
            fTrackColors = GetRandomColors(fTracks.Count);
        }
Пример #5
0
        /// <summary>
        /// Sets the sizes of canvas.
        /// </summary>
        /// <param name="imageSize">The size of canvas.</param>
        /// <param name="noRedraw">Flag of the need to redraw.</param>
        protected void SetImageSize(ExtSize imageSize, bool noRedraw = false)
        {
            if (AutoScroll && !imageSize.IsEmpty)
            {
                AutoScrollMinSize = new Size(imageSize.Width + Padding.Horizontal, imageSize.Height + Padding.Vertical);
            }

            if (!noRedraw)
            {
                Invalidate();
            }
        }
Пример #6
0
        public HyperView() : base()
        {
            CenteredImage = false;

            fAcceptFontChange = true;
            fChunks           = new List <BBTextChunk>();
            fCurrentLink      = null;
            fHeights          = new List <int>();
            fLines            = new StringList();
            fLines.OnChange  += LinesChanged;
            fLinkColor        = Colors.Blue;
            fTextSize         = ExtSize.Empty;
        }
Пример #7
0
        /// <summary>
        ///   Construct a new timeline.
        /// </summary>
        public TimelineViewer()
        {
            AutoScroll   = true;
            ResizeRedraw = true;

            BackColor      = Color.FromArgb(64, 64, 64);
            DoubleBuffered = true;

            SetStyle(
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.Opaque |
                ControlStyles.OptimizedDoubleBuffer |
                ControlStyles.ResizeRedraw |
                ControlStyles.Selectable |
                ControlStyles.UserPaint, true);

            fToolTip = new ToolTip();
            fToolTip.AutoPopDelay = 15000;
            fToolTip.InitialDelay = 250;
            fToolTip.OwnerDraw    = true;
            fToolTip.Draw        += ToolTip_Draw;
            fToolTip.Popup       += ToolTip_Popup;

            fBackgroundColor          = Color.Black;
            fGridAlpha                = 40;
            fImageSize                = ExtSize.Empty;
            fLabelsFormat             = new StringFormat(StringFormatFlags.FitBlackBox);
            fPlayheadExtents          = new SizeF(5, 16);
            fRenderingOffset          = PointF.Empty;
            fRenderingOffsetBeforePan = PointF.Empty;
            fRenderingScale           = 1.0f;
            fSelectedFrames           = new List <EventFrame>();
            fSelectionPen             = new Pen(Color.LightGray, 1)
            {
                DashStyle = DashStyle.Dot
            };
            fSelectionRectangle = Rectangle.Empty;
            fTrackBorderSize    = 2;
            fTrackHeight        = 20;
            fTrackLabelWidth    = 100;
            fTrackSpacing       = 1;
            fTracks             = new List <Track>();

            // Set up the font to use to draw the track labels
            float emHeightForLabel = EmHeightForLabel("WM_g^~", TrackHeight);

            fLabelFont = new Font(DefaultFont.FontFamily, emHeightForLabel - 2);

            RecreatePens();
        }
Пример #8
0
        public IImage GetPrintableImage()
        {
            ExtSize imageSize = GetImageSize();
            var     frameRect = new Rectangle(0, 0, imageSize.Width, imageSize.Height);

            Image image;

            using (var gfx = CreateGraphics()) {
                image = new Metafile(gfx.GetHdc(), frameRect, MetafileFrameUnit.Pixel, EmfType.EmfOnly);
            }

            using (Graphics gfx = Graphics.FromImage(image)) {
                RenderStaticImage(gfx, OutputType.Printer);
            }

            return(new ImageHandler(image));
        }
Пример #9
0
        public HyperView() : base()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint |
                     ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
            UpdateStyles();

            BorderStyle    = BorderStyle.Fixed3D;
            DoubleBuffered = true;
            TabStop        = true;

            fAcceptFontChange = true;
            fChunks           = new List <BBTextChunk>();
            fCurrentLink      = null;
            fHeights          = new List <int>();
            fLines            = new StringList();
            fLines.OnChange  += LinesChanged;
            fLinkColor        = Color.Blue;
            fTextSize         = ExtSize.Empty;
        }
Пример #10
0
        /// <summary>
        /// Sets the sizes of canvas.
        /// </summary>
        /// <param name="imageSize">The size of canvas.</param>
        /// <param name="noRedraw">Flag of the need to redraw.</param>
        protected void SetImageSize(ExtSize imageSize, bool noRedraw = false)
        {
            if (!imageSize.IsEmpty)
            {
                fImageSize = new Size(imageSize.Width, imageSize.Height);

                Size clientSize = fViewport.Size;
                int  canvWidth  = Math.Max(imageSize.Width, clientSize.Width);
                int  canvHeight = Math.Max(imageSize.Height, clientSize.Height);
                fCanvas.Size = new Size(canvWidth, canvHeight);

                base.UpdateScrollSizes();
                UpdateProperties();
            }

            if (!noRedraw)
            {
                Invalidate();
            }
        }
Пример #11
0
        public HyperView()
        {
            SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint |
                     ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
            UpdateStyles();

            BorderStyle    = BorderStyle.Fixed3D;
            DoubleBuffered = true;
            TabStop        = true;

            fAcceptFontChange = true;
            fChunks           = new List <BBTextChunk>();
            fCurrentLink      = null;
            fHeights          = new List <int>();
            fLines            = new StringList();
            fLines.OnChange  += LinesChanged;
            fLinkColor        = Color.Blue;
            fTextSize         = ExtSize.Empty;
            fStrFormat        = new StringFormat(StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap | StringFormatFlags.NoClip);
            fWordWrap         = true;
        }
Пример #12
0
        public void Changed()
        {
            fModel.CreateBrushes();

            switch (fChartType)
            {
            case CircleChartType.Ancestors:
                fModel.BuildAncTree();
                break;

            case CircleChartType.Descendants:
                fModel.BuildDescTree();
                break;
            }

            fModel.AdjustBounds();

            ExtSize boundary = GetImageSize();

            SetImageSize(boundary, false);
        }
Пример #13
0
        public IImage GetPrintableImage()
        {
            ExtSize imageSize = GetImageSize();
            var     frameRect = new Rectangle(0, 0, imageSize.Width, imageSize.Height);

            /*Image image;
             * using (var gfx = CreateGraphics()) {
             *  image = new Metafile(gfx.GetHdc(), frameRect, MetafileFrameUnit.Pixel, EmfType.EmfOnly);
             * }
             * using (Graphics gfx = Graphics.FromImage(image)) {
             *  RenderStaticImage(gfx, true);
             * }
             */

            var image = new Bitmap(imageSize.Width, imageSize.Height, PixelFormat.Format24bppRgb);

            using (Graphics gfx = new Graphics(image)) {
                RenderStaticImage(gfx, true);
            }

            return(new ImageHandler(image));
        }
Пример #14
0
        private void TryRenderTreeSlice(ITreeChart treeBox, int index, GDMIndividualRecord currentPatriarch)
        {
            IndiObj indi = fIndiQueue[index];

            fProcessed.Add(indi.IRec.XRef);

            int         depthLimit  = 3;
            float       scaleFactor = 1.0f;
            int         tries       = 0;
            RenderStage stage       = RenderStage.Normal;

            while (true)
            {
                treeBox.Model.DepthLimit = depthLimit;
                treeBox.Model.Scale      = scaleFactor;
                treeBox.GenChart(indi.IRec, indi.TreeKind, false);
                tries += 1;

                ExtSize imageSize = treeBox.GetImageSize();
                var     sf        = GfxHelper.ZoomToFit(imageSize.Width, imageSize.Height, fPageSize.GetWidth(), fPageSize.GetHeight());

                if (sf < 1.0f)
                {
                    // need to reduce image's size
                    switch (stage)
                    {
                    case RenderStage.Normal:
                        depthLimit -= 1;
                        stage       = RenderStage.Shrink;
                        break;

                    case RenderStage.Grow:
                        depthLimit -= 1;
                        stage       = RenderStage.Break;
                        break;

                    case RenderStage.Shrink:
                        scaleFactor = sf;
                        stage       = RenderStage.Break;
                        break;
                    }
                }
                else if (sf > 1.0f)
                {
                    // need to increase image's size
                    switch (stage)
                    {
                    case RenderStage.Normal:
                    case RenderStage.Grow:
                        depthLimit += 1;
                        stage       = RenderStage.Grow;
                        break;

                    case RenderStage.Shrink:
                        scaleFactor = sf;
                        stage       = RenderStage.Break;
                        break;
                    }
                }

                if (stage == RenderStage.Break || tries > 10)
                {
                    break;
                }
            }

            scaleFactor = Math.Min(1.0f, scaleFactor);
            treeBox.Model.DepthLimit = depthLimit;
            treeBox.Model.Scale      = scaleFactor;
            treeBox.GenChart(indi.IRec, indi.TreeKind, false);
            treeBox.RenderImage(RenderTarget.Printer, true);

            var indiNums = new GKVarCache <GDMIndividualRecord, int>();

            for (int i = 0; i < treeBox.Model.Persons.Count; i++)
            {
                TreeChartPerson     person  = treeBox.Model.Persons[i];
                GDMIndividualRecord indiRec = person.Rec;
                if (indiRec == null)
                {
                    continue;
                }

                int iNum = indiNums[indiRec];

                var    offset = treeBox.Model.GetOffsets();
                int    ix     = offset.X + person.Rect.Left;
                int    iy     = offset.Y + person.Rect.Top - (int)fTextFont.Size;
                string iRef   = indiRec.XRef + "#" + iNum;
                fRenderer.DrawAnchor(iRef, iRef, fTextFont, null, ix, iy);

                iNum += 1;
                indiNums[indiRec] = iNum;

                if (!person.CanExpand)
                {
                    continue;
                }

                ix   = offset.X + person.Rect.Left;
                iy   = offset.Y + person.Rect.Bottom;
                iRef = indiRec.XRef + "#" + iNum;
                fRenderer.DrawHyperlink(iRef, iRef, fLinkFont, null, ix, iy);

                if (person.HasFlag(PersonFlag.pfAncWalk))
                {
                    if (person.HasFlag(PersonFlag.pfHasInvAnc) && !IsPatriarchsDescendant(indiRec, currentPatriarch))
                    {
                        CheckQueue(indiRec, TreeChartKind.ckAncestors);
                    }
                }
                else if (person.HasFlag(PersonFlag.pfDescWalk))
                {
                    if (person.HasFlag(PersonFlag.pfSpouse))
                    {
                        if (person.HasFlag(PersonFlag.pfHasInvAnc) && !IsPatriarchsDescendant(indiRec, currentPatriarch))
                        {
                            CheckQueue(indiRec, TreeChartKind.ckAncestors);
                        }
                    }
                    else
                    {
                        if (person.HasFlag(PersonFlag.pfHasInvDesc) && TreeTools.PL_SearchAnc(fTree, indiRec, currentPatriarch, true))
                        {
                            CheckQueue(indiRec, TreeChartKind.ckDescendants);
                        }
                    }
                }
            }
        }
Пример #15
0
        private void ArrangeText()
        {
            try {
                fAcceptFontChange = false;
                fHeights.Clear();

                Graphics gfx = CreateGraphics();
                //gfx.TextRenderingHint = TextRenderingHint.AntiAlias;
                try {
                    int xPos       = 0;
                    int yPos       = 0;
                    int xMax       = 0;
                    int lineHeight = 0;

                    string text    = fLines.Text;
                    Font   defFont = this.Font;
                    SizeF  csz     = this.ClientSize;
                    SizeF  zerosz  = new SizeF(0f, 0f);

                    var parser = new BBTextParser(AppHost.GfxProvider, defFont.SizeInPoints,
                                                  new ColorHandler(fLinkColor), new ColorHandler(ForeColor));

                    parser.ParseText(fChunks, text);

                    int line        = -1;
                    int chunksCount = fChunks.Count;
                    int k           = 0;
                    while (k < chunksCount)
                    {
                        BBTextChunk chunk       = fChunks[k];
                        bool        recalcChunk = false;

                        if (line != chunk.Line)
                        {
                            line = chunk.Line;

                            if (line > 0)
                            {
                                yPos += lineHeight;
                                fHeights.Add(lineHeight);
                            }

                            xPos       = 0;
                            lineHeight = 0;
                        }

                        int prevX = xPos;
                        int prevY = yPos;

                        string chunkStr = chunk.Text;
                        if (!string.IsNullOrEmpty(chunkStr))
                        {
                            using (var font = new Font(defFont.Name, chunk.Size, (sdFontStyle)chunk.Style, defFont.Unit)) {
                                SizeF strSize = gfx.MeasureString(chunkStr, font, zerosz, fStrFormat);

                                if (fWordWrap)
                                {
                                    int wBound = xPos + 2 * fBorderWidth;
                                    if (wBound + strSize.Width > csz.Width)
                                    {
                                        int lastIndex = chunkStr.Length - 1;
                                        while (true)
                                        {
                                            int spPos = chunkStr.LastIndexOf(' ', lastIndex);
                                            if (spPos <= 0)
                                            {
                                                // the beginning of the chunk is reached and there are no more words to carry
                                                chunk.Text = chunkStr.Substring(0, lastIndex + 1);
                                                strSize    = gfx.MeasureString(chunkStr, font, zerosz, fStrFormat);
                                                // the current chunk still does not fit into the area
                                                if (wBound + strSize.Width > csz.Width)
                                                {
                                                    // this is not the only chunk on this line
                                                    if (k > 0 && fChunks[k - 1].Line == chunk.Line)
                                                    {
                                                        // transfer the current chunk to the next line
                                                        // and recount it again at the next iteration
                                                        ShiftChunks(k, chunksCount);
                                                        recalcChunk = true;
                                                    }
                                                }
                                                break;
                                            }

                                            string newChunk = chunkStr.Substring(0, spPos);
                                            strSize = gfx.MeasureString(newChunk, font, zerosz, fStrFormat);
                                            if (wBound + strSize.Width < csz.Width)
                                            {
                                                var secondPart = chunk.Clone();
                                                secondPart.Text  = chunkStr.Substring(spPos + 1);
                                                secondPart.Line += 1;
                                                fChunks.Insert(k + 1, secondPart);
                                                chunksCount += 1;

                                                // shift next chunks
                                                ShiftChunks(k + 2, chunksCount);

                                                chunk.Text = newChunk;
                                                break;
                                            }
                                            else
                                            {
                                                lastIndex = spPos - 1;
                                            }
                                        }
                                    }
                                }

                                chunk.Width = (int)strSize.Width;

                                xPos += chunk.Width;
                                if (xMax < xPos)
                                {
                                    xMax = xPos;
                                }

                                int h = (int)strSize.Height;
                                if (lineHeight < h)
                                {
                                    lineHeight = h;
                                }
                            }

                            if (!string.IsNullOrEmpty(chunk.URL))
                            {
                                chunk.LinkRect = ExtRect.CreateBounds(prevX, prevY, xPos - prevX, lineHeight);
                            }
                        }

                        if (!recalcChunk)
                        {
                            k++;
                        }
                    }

                    fTextSize = new ExtSize(xMax + 2 * fBorderWidth, yPos + 2 * fBorderWidth);
                } finally {
                    gfx.Dispose();
                    fAcceptFontChange = true;
                    AdjustViewport(fTextSize);
                }
            } catch (Exception ex) {
                Logger.LogWrite("HyperView.ArrangeText(): " + ex.Message);
            }
        }
Пример #16
0
        protected override void InternalGenerate()
        {
            try
            {
                {
                    string title = "Trees Album";//LangMan.LS(LSID.LSID_TreesAlbum)

                    fDocument.AddTitle(title);
                    fDocument.AddSubject("");
                    fDocument.AddAuthor("");
                    fDocument.AddCreator(GKData.APP_TITLE);
                    fDocument.Open();

                    BaseFont baseFont = BaseFont.CreateFont(Environment.ExpandEnvironmentVariables(@"%systemroot%\fonts\Times.ttf"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
                    fTitleFont   = new itFont(baseFont, 30f, itFont.BOLD);
                    fChapFont    = new itFont(baseFont, 16f, itFont.BOLD, BaseColor.BLACK);
                    fSubchapFont = new itFont(baseFont, 14f, itFont.BOLD, BaseColor.BLACK);
                    fLinkFont    = new itFont(baseFont, 8f, itFont.UNDERLINE, BaseColor.BLUE);
                    fTextFont    = new itFont(baseFont, 8f, itFont.NORMAL, BaseColor.BLACK);
                    fBoldFont    = new itFont(baseFont, 8f, itFont.BOLD, BaseColor.BLACK);
                    fSymFont     = new itFont(baseFont, 12f, itFont.BOLD, BaseColor.BLACK);

                    float halfpage = (fDocument.Top - fDocument.Bottom - (fTitleFont.Size) * 4) / 2f;
                    fDocument.Add(new Paragraph(Chunk.NEWLINE)
                    {
                        SpacingAfter = halfpage
                    });
                    fDocument.Add(new Paragraph(title, fTitleFont)
                    {
                        Alignment = Element.ALIGN_CENTER
                    });
                    fDocument.NewPage();

                    PreparePatriarchs();

                    var   itPS       = fDocument.PageSize;
                    float pageHeight = itPS.Height;
                    float pageWidth  = itPS.Width;

                    var renderer = new TreeChartPDFRenderer(pageWidth, pageHeight);
                    renderer.SetTarget(fPdfWriter.DirectContent, false);

                    // TODO: replace by local options in TreeChartBox
                    bool prevKinship = GlobalOptions.Instance.ChartOptions.Kinship;
                    GlobalOptions.Instance.ChartOptions.Kinship = false;

                    var treeBox = AppHost.Container.Resolve <ITreeChartBox>();
                    treeBox.SetRenderer(renderer);
                    treeBox.Base       = fBase;
                    treeBox.Options    = GlobalOptions.Instance.ChartOptions;
                    treeBox.DepthLimit = 3;
                    treeBox.Height     = (int)pageHeight;
                    treeBox.Width      = (int)pageWidth;

                    int num = fPatList.Count;
                    for (int i = 0; i < num; i++)
                    {
                        string iName = fPatList[i];
                        GEDCOMIndividualRecord iRec = fPatList.GetObject(i) as GEDCOMIndividualRecord;

                        treeBox.SetScale(1.0f);
                        treeBox.GenChart(iRec, TreeChartKind.ckDescendants, false);

                        ExtSize imageSize   = treeBox.GetImageSize();
                        float   scaleFactor = SysUtils.ZoomToFit(imageSize.Width,
                                                                 imageSize.Height,
                                                                 pageWidth, pageHeight);
                        scaleFactor = (scaleFactor > 1.0f) ? 1.0f : scaleFactor;

                        treeBox.SetScale(scaleFactor);
                        treeBox.RenderStatic(BackgroundMode.bmNone, true);

                        fDocument.NewPage();
                    }

                    GlobalOptions.Instance.ChartOptions.Kinship = prevKinship;
                }
            }
            catch (Exception ex)
            {
                Logger.LogWrite("TreesAlbumExporter.InternalGenerate(): " + ex.Message);
                throw;
            }
        }
Пример #17
0
        /* TODO(zsv): Need to find an appropriate icon in the general style
         * for the main toolbar - screenshot capture for windows with charts. */
        public void SaveSnapshot(string fileName)
        {
            string ext = SysUtils.GetFileExtension(fileName);

            ExtSize imageSize = GetImageSize();

            if ((ext == ".bmp" || ext == ".jpg") && imageSize.Width >= 65535)
            {
                AppHost.StdDialogs.ShowError(LangMan.LS(LSID.LSID_TooMuchWidth));
            }
            else
            {
                ImageFormat imFmt = ImageFormat.Png;
                if (ext == ".bmp")
                {
                    imFmt = ImageFormat.Bitmap;
                }

                /*else
                 *  if (ext == ".emf") { imFmt = ImageFormat.Emf; }*/
                else
                if (ext == ".png")
                {
                    imFmt = ImageFormat.Png;
                }
                else
                if (ext == ".gif")
                {
                    imFmt = ImageFormat.Gif;
                }
                else
                if (ext == ".jpg")
                {
                    imFmt = ImageFormat.Jpeg;
                }

                /*Image pic;
                 * if (Equals(imFmt, ImageFormat.Emf)) {
                 *  using (var gfx = CreateGraphics()) {
                 *      pic = new Metafile(fileName, gfx.GetHdc());
                 *  }
                 * } else {
                 *  pic = new Bitmap(imageSize.Width, imageSize.Height, PixelFormat.Format24bppRgb);
                 * }*/
                Bitmap pic = new Bitmap(imageSize.Width, imageSize.Height, PixelFormat.Format24bppRgb);

                try
                {
                    //using (Graphics gfx = Graphics.FromImage(pic)) {
                    using (Graphics gfx = new Graphics(pic)) {
                        RenderStaticImage(gfx, false);
                    }

                    ((Bitmap)pic).Save(fileName, imFmt);
                }
                finally
                {
                    pic.Dispose();
                }
            }
        }
Пример #18
0
 private static extern Bool UpdateLayeredWindow(IntPtr hWnd, IntPtr hdcDst, ref ExtPoint pptDst,
                                                ref ExtSize psize, IntPtr hDcSrc, ref ExtPoint pprSrc, int crKey, ref ExtBlendFunction pblend, int dwFlags);
Пример #19
0
        private void ArrangeText()
        {
            try
            {
                fAcceptFontChange = false;
                fHeights.Clear();

                Graphics gfx = CreateGraphics();
                try
                {
                    int xPos       = 0;
                    int yPos       = 0;
                    int xMax       = 0;
                    int lineHeight = 0;

                    string text    = fLines.Text;
                    Font   defFont = this.Font;

                    var parser = new BBTextParser(AppHost.GfxProvider, defFont.SizeInPoints,
                                                  new ColorHandler(fLinkColor),
                                                  new ColorHandler(ForeColor));

                    parser.ParseText(fChunks, text);

                    int line        = -1;
                    int chunksCount = fChunks.Count;
                    for (int k = 0; k < chunksCount; k++)
                    {
                        BBTextChunk chunk = fChunks[k];

                        if (line != chunk.Line)
                        {
                            line = chunk.Line;

                            if (line > 0)
                            {
                                yPos += lineHeight;
                                fHeights.Add(lineHeight);
                            }

                            xPos       = 0;
                            lineHeight = 0;
                        }

                        if (!string.IsNullOrEmpty(chunk.Text))
                        {
                            using (var font = new Font(defFont.Name, chunk.Size, (sdFontStyle)chunk.Style, defFont.Unit)) {
                                SizeF strSize = gfx.MeasureString(chunk.Text, font);
                                chunk.Width = (int)strSize.Width;

                                xPos += chunk.Width;
                                if (xMax < xPos)
                                {
                                    xMax = xPos;
                                }

                                int h = (int)strSize.Height;
                                if (lineHeight < h)
                                {
                                    lineHeight = h;
                                }
                            }
                        }
                    }

                    fTextSize = new ExtSize(xMax + 2 * fBorderWidth, yPos + 2 * fBorderWidth);
                }
                finally
                {
                    gfx.Dispose();
                    fAcceptFontChange = true;
                    AdjustViewport(fTextSize);
                }
            }
            catch (Exception ex)
            {
                Logger.LogWrite("HyperView.ArrangeText(): " + ex.Message);
            }
        }
Пример #20
0
        private void ArrangeText()
        {
            try {
                fAcceptFontChange = false;
                fHeights.Clear();

                try {
                    int xPos       = 0;
                    int yPos       = 0;
                    int xMax       = 0;
                    int lineHeight = 0;

                    string text = fLines.Text.Trim();
                    if (!string.IsNullOrEmpty(text))
                    {
                        Font defFont = this.Font;
                        var  parser  = new BBTextParser(AppHost.GfxProvider, defFont.Size,
                                                        new ColorHandler(fLinkColor), new ColorHandler(TextColor));

                        parser.ParseText(fChunks, text);

                        int line        = -1;
                        int chunksCount = fChunks.Count;
                        for (int k = 0; k < chunksCount; k++)
                        {
                            BBTextChunk chunk = fChunks[k];

                            if (line != chunk.Line)
                            {
                                line = chunk.Line;

                                if (line > 0)
                                {
                                    yPos += lineHeight;
                                    fHeights.Add(lineHeight);
                                }

                                xPos       = 0;
                                lineHeight = 0;
                            }

                            int prevX = xPos;
                            int prevY = yPos;

                            if (!string.IsNullOrEmpty(chunk.Text))
                            {
                                using (var font = new Font(defFont.FamilyName, chunk.Size, (sdFontStyle)chunk.Style)) {
                                    SizeF strSize = font.MeasureString(chunk.Text);
                                    chunk.Width = (int)strSize.Width;

                                    xPos += chunk.Width;
                                    if (xMax < xPos)
                                    {
                                        xMax = xPos;
                                    }

                                    int h = (int)strSize.Height;
                                    if (lineHeight < h)
                                    {
                                        lineHeight = h;
                                    }
                                }

                                if (!string.IsNullOrEmpty(chunk.URL))
                                {
                                    chunk.LinkRect = ExtRect.CreateBounds(prevX, prevY, xPos - prevX, lineHeight);
                                }
                            }
                        }
                    }

                    fTextSize = new ExtSize(xMax + 2 * fBorderWidth, yPos + 2 * fBorderWidth);
                } finally {
                    fAcceptFontChange = true;
                    SetImageSize(fTextSize);
                }
            } catch (Exception ex) {
                Logger.LogWrite("HyperView.ArrangeText(): " + ex.Message);
            }
        }
Пример #21
0
        /* TODO(zsv): Need to find an appropriate icon in the general style
         * for the main toolbar - screenshot capture for windows with charts. */
        public void SaveSnapshot(string fileName)
        {
            string ext = SysUtils.GetFileExtension(fileName);

            ExtSize imageSize = GetImageSize();

            if (ext == ".svg")
            {
                try {
                    SetSVGMode(true, fileName, imageSize.Width, imageSize.Height);

                    using (var gfx = CreateGraphics()) {
                        RenderStaticImage(gfx, OutputType.SVG);
                    }
                } finally {
                    SetSVGMode(false, "", 0, 0);
                }

                return;
            }

            if ((ext == ".bmp" || ext == ".jpg") && imageSize.Width >= 65535)
            {
                AppHost.StdDialogs.ShowError(LangMan.LS(LSID.LSID_TooMuchWidth));
            }
            else
            {
                ImageFormat imFmt = ImageFormat.Png;
                if (ext == ".bmp")
                {
                    imFmt = ImageFormat.Bmp;
                }
                else
                if (ext == ".emf")
                {
                    imFmt = ImageFormat.Emf;
                }
                else
                if (ext == ".png")
                {
                    imFmt = ImageFormat.Png;
                }
                else
                if (ext == ".gif")
                {
                    imFmt = ImageFormat.Gif;
                }
                else
                if (ext == ".jpg")
                {
                    imFmt = ImageFormat.Jpeg;
                }

                Image pic;
                if (Equals(imFmt, ImageFormat.Emf))
                {
                    using (var gfx = CreateGraphics()) {
                        pic = new Metafile(fileName, gfx.GetHdc());
                    }
                }
                else
                {
                    pic = new Bitmap(imageSize.Width, imageSize.Height, PixelFormat.Format24bppRgb);
                }

                try
                {
                    using (Graphics gfx = Graphics.FromImage(pic)) {
                        RenderStaticImage(gfx, OutputType.StdFile);
                    }

                    pic.Save(fileName, imFmt);
                }
                finally
                {
                    pic.Dispose();
                }
            }
        }
Пример #22
0
        public bool IsLandscape()
        {
            ExtSize imageSize = GetImageSize();

            return(imageSize.Height < imageSize.Width);
        }
Пример #23
0
        /* TODO(zsv): Need to find an appropriate icon in the general style
         * for the main toolbar - screenshot capture for windows with charts. */
        public void SaveSnapshot(string fileName)
        {
            string ext = FileHelper.GetFileExtension(fileName);

            ExtSize imageSize = GetImageSize();

            if (ext == ".svg")
            {
                var prevRenderer = fRenderer;
                SetRenderer(new SVGRenderer(fileName, imageSize.Width, imageSize.Height));
                fRenderer.BeginDrawing();
                try {
                    using (var gfx = CreateGraphics()) {
                        fRenderer.SetTarget(gfx);

                        RenderImage(RenderTarget.SVG);
                    }
                } finally {
                    fRenderer.EndDrawing();
                    SetRenderer(prevRenderer);
                }

                return;
            }

            if ((ext == ".bmp" || ext == ".jpg") && imageSize.Width >= 65535)
            {
                AppHost.StdDialogs.ShowError(LangMan.LS(LSID.LSID_TooMuchWidth));
            }
            else
            {
                ImageFormat imFmt = ImageFormat.Png;
                if (ext == ".bmp")
                {
                    imFmt = ImageFormat.Bitmap;
                }
                else if (ext == ".png")
                {
                    imFmt = ImageFormat.Png;
                }
                else if (ext == ".gif")
                {
                    imFmt = ImageFormat.Gif;
                }
                else if (ext == ".jpg")
                {
                    imFmt = ImageFormat.Jpeg;
                } /*else if (ext == ".emf") {
                   * imFmt = ImageFormat.Emf;
                   * }*/

                /*Image pic;
                 * if (Equals(imFmt, ImageFormat.Emf)) {
                 *  using (var gfx = CreateGraphics()) {
                 *      pic = new Metafile(fileName, gfx.GetHdc());
                 *  }
                 * } else {
                 *  pic = new Bitmap(imageSize.Width, imageSize.Height, PixelFormat.Format24bppRgb);
                 * }*/

                Bitmap pic = new Bitmap(imageSize.Width, imageSize.Height, PixelFormat.Format24bppRgb);
                try {
                    using (Graphics gfx = new Graphics(pic)) {
                        fRenderer.SetTarget(gfx);
                        RenderImage(RenderTarget.RasterFile);
                    }

                    pic.Save(fileName, imFmt);
                } finally {
                    pic.Dispose();
                }
            }
        }
Пример #24
0
        private void ArrangeText()
        {
            try {
                SuspendLayout();

                fAcceptFontChange = false;
                fHeights.Clear();

                try {
                    int xPos       = 0;
                    int yPos       = 0;
                    int xMax       = 0;
                    int lineHeight = 0;

                    string text     = fLines.Text;
                    Font   defFont  = this.Font;
                    float  maxWidth = this.ClientSize.Width - (2 * fBorderWidth);

                    text = SysUtils.StripHTML(text);

                    var parser = new BBTextParser(AppHost.GfxProvider, defFont.Size,
                                                  new ColorHandler(fLinkColor), new ColorHandler(TextColor));

                    parser.ParseText(fChunks, text);

                    int line        = -1;
                    int chunksCount = fChunks.Count;
                    int k           = 0;
                    while (k < chunksCount)
                    {
                        BBTextChunk chunk       = fChunks[k];
                        bool        recalcChunk = false;

                        if (line != chunk.Line)
                        {
                            line = chunk.Line;

                            if (line > 0)
                            {
                                yPos += lineHeight;
                                fHeights.Add(lineHeight);
                            }

                            xPos       = 0;
                            lineHeight = 0;
                        }

                        int prevX = xPos;
                        int prevY = yPos;

                        string chunkStr = chunk.Text;
                        if (!string.IsNullOrEmpty(chunkStr))
                        {
                            using (var font = new Font(defFont.FamilyName, chunk.Size, (EDFontStyle)chunk.Style)) {
                                SizeF strSize = font.MeasureString(chunkStr);

                                if (fWordWrap && xPos + strSize.Width > maxWidth)
                                {
                                    int    lastPos = 0, prevPos = 0;
                                    string tempStr, prevStr = string.Empty;
                                    int    sliceType = -1;
                                    while (true)
                                    {
                                        tempStr = GetSlice(chunkStr, ref lastPos, ref sliceType);
                                        strSize = font.MeasureString(tempStr);
                                        if (xPos + strSize.Width <= maxWidth)
                                        {
                                            prevStr = tempStr;
                                            prevPos = lastPos;
                                        }
                                        else
                                        {
                                            if (sliceType == 0)
                                            {
                                                // first word
                                                if (xPos == 0)
                                                {
                                                    string tail = chunkStr.Substring(lastPos);
                                                    SplitChunk(chunk, k, tempStr, tail, ref chunksCount);
                                                }
                                                else
                                                {
                                                    ShiftChunks(k, chunksCount);
                                                    recalcChunk = true;
                                                }
                                                break;
                                            }
                                            else if (sliceType == 1 || sliceType == 2)
                                            {
                                                // middle or tail word
                                                string tail = chunkStr.Substring(prevPos);
                                                SplitChunk(chunk, k, prevStr, tail, ref chunksCount);
                                                break;
                                            }
                                            else if (sliceType == 3)
                                            {
                                                // one first and last word, nothing to do
                                                break;
                                            }
                                        }
                                    }
                                }

                                strSize     = font.MeasureString(chunk.Text);
                                chunk.Width = (int)strSize.Width;

                                xPos += chunk.Width;
                                if (xMax < xPos)
                                {
                                    xMax = xPos;
                                }

                                int h = (int)strSize.Height;
                                if (lineHeight < h)
                                {
                                    lineHeight = h;
                                }
                            }

                            if (!string.IsNullOrEmpty(chunk.URL))
                            {
                                chunk.LinkRect = ExtRect.CreateBounds(prevX, prevY, xPos - prevX, lineHeight);
                            }
                        }

                        if (!recalcChunk)
                        {
                            k++;
                        }
                    }

                    fTextSize = new ExtSize(xMax + 2 * fBorderWidth, yPos + 2 * fBorderWidth);
                } finally {
                    fAcceptFontChange = true;
                    SetImageSize(fTextSize);

                    ResumeLayout();
                }
            } catch (Exception ex) {
                Logger.WriteError("HyperView.ArrangeText()", ex);
            }
        }