protected override LeadRectD GetBoundingRectangle() { LeadRectD rc = base.GetBoundingRectangle(); double radius = _centerPointRadius.Value; if (!(double.IsInfinity(radius) || (double.IsInfinity(radius))) && !rc.IsEmpty) { rc.Inflate(radius, radius); } return(rc); }
private void DrawBarcodeData(Graphics g, RasterImage image, BarcodeData data, StringFormat sf, Brush brush, Pen pen) { LeadRect rect = data.Bounds; LeadRectD rc = new LeadRectD(rect.X, rect.Y, rect.Width, rect.Height); string line = BarcodeEngine.GetSymbologyFriendlyName(data.Symbology); if (FourPoints && data.Symbology != BarcodeSymbology.Aztec && data.Symbology != BarcodeSymbology.Maxi && data.Symbology != BarcodeSymbology.MicroQR) { LeadPointD[] pointsL = new LeadPointD[4]; Point[] points = new Point[4]; pointsL[0].X = ((int)rc.Left & 0xffff); pointsL[0].Y = ((int)rc.Left >> 16); pointsL[1].X = ((int)rc.Top & 0xffff); pointsL[1].Y = ((int)rc.Top >> 16); pointsL[2].X = ((int)rc.Width & 0xffff); pointsL[2].Y = ((int)rc.Width >> 16); pointsL[3].X = ((int)rc.Height & 0xffff); pointsL[3].Y = ((int)rc.Height >> 16); _rasterImageViewer.ImageTransform.TransformPoints(pointsL); for (int i = 0; i < 4; i++) { points[i].X = (int)pointsL[i].X; points[i].Y = (int)pointsL[i].Y; } g.DrawPolygon(pen, points); SizeF size = g.MeasureString(line, Font, points[2].X - points[0].X, sf); rc.Width = (int)size.Width + 1; rc.Height = (int)size.Height + 1; g.FillRectangle(brush, points[0].X, points[0].Y, (int)rc.Width, (int)rc.Height); g.DrawString(line, Font, Brushes.White, new RectangleF(points[0].X, points[0].Y, (int)rc.Width, (int)rc.Height), sf); } else { rc = _rasterImageViewer.ImageTransform.TransformRect(rc); rc.Inflate(3, 3); if (rc.Width < 10 || rc.Height < 10) { return; } g.DrawRectangle(pen, (int)rc.X, (int)rc.Y, (int)rc.Width, (int)rc.Height); SizeF size = g.MeasureString(line, Font, (int)rc.Width, sf); rc.Width = (int)size.Width + 1; rc.Height = (int)size.Height + 1; g.FillRectangle(brush, (int)rc.X, (int)rc.Y, (int)rc.Width, (int)rc.Height); g.DrawString(line, Font, Brushes.White, new RectangleF((int)rc.X, (int)rc.Y, (int)rc.Width, (int)rc.Height), sf); } }
private void AddHighlight(LeadRect highlightBounds, string color) { if (masterSheet == null) { return; } masterSheetViewer.BeginUpdate(); //Now we can calculate the object bounds correctly LeadRectD rect = BoundsToAnnotations(highlightBounds); rect.Inflate(INFLATE, INFLATE); annotationField.HiliteColor = color; annotationField.Rect = rect; masterSheetViewer.EndUpdate(); }
public void ShowRichTextDialog(AnnRichTextObject richTextObject) { if ((richTextObject != null) && !richTextObject.IsLocked && !richTextObject.Bounds.IsEmpty) { _tb = new RichTextBox(); _tb.Multiline = true; _tb.HideSelection = false; _tb.Rtf = richTextObject.Rtf; LeadRectD bounds = _container.Mapper.RectFromContainerCoordinates(richTextObject.Bounds, richTextObject.FixedStateOperations); bounds.Inflate(20, 20); _tb.Location = new Point((int)bounds.X, (int)bounds.Y); _tb.Size = new Size((int)bounds.Width, (int)bounds.Height); _tb.LostFocus += new EventHandler(tb_LostFocus); _tb.KeyDown += new KeyEventHandler(tb_KeyDown); _tb.MouseDown += new MouseEventHandler(tb_MouseDown); _toolBar = new RichTextMenu(_tb); _toolBar.Location = new Point(200, 200); _toolBar.Closing += new System.ComponentModel.CancelEventHandler(_toolBar_Closing); _toolBar.Show(_tb.Parent); var imageViewerAutomationControl = _owner as ImageViewerAutomationControl; if (imageViewerAutomationControl != null) { imageViewerAutomationControl.ImageViewer.Controls.Add(_tb); } _tb.Focus(); _tb.SelectAll(); IsEditingText = true; } }
private void _rasterImageViewer_PostImagePaint(object sender, ImageViewerRenderEventArgs e) { RasterImage image = _rasterImageViewer.Image; if (image != null && !_disableExtraDrawing) { if (ShowBarcodes) { using (StringFormat sf = new StringFormat()) using (Brush normalBrush = new SolidBrush(Color.FromArgb(200, Color.DarkGreen))) using (Pen normalPen = new Pen(Color.FromArgb(180, Color.DarkGreen), 4)) using (Brush selectedBrush = new SolidBrush(Color.FromArgb(200, Color.Blue))) using (Pen selectedPen = new Pen(Color.FromArgb(180, Color.Blue), 4)) { sf.FormatFlags = StringFormatFlags.NoWrap; // Draw the barcodes for this page int index = 0; PageBarcodes pageBarcodes = _documentBarcodes.Pages[image.Page - 1]; foreach (BarcodeData data in pageBarcodes.Barcodes) { if (index == pageBarcodes.SelectedIndex) { DrawBarcodeData(e.PaintEventArgs.Graphics, image, data, sf, selectedBrush, selectedPen); } else { DrawBarcodeData(e.PaintEventArgs.Graphics, image, data, sf, normalBrush, normalPen); } index++; } } } if (_viewerRegion && _rasterImageViewer.Image.Page == _viewerRegionPage) { // Draw an alpha brush around the image region if (!_rasterImageViewer.Image.HasRegion) { _rasterImageViewer.Image.SetRegion(null, RegionG, RasterRegionCombineMode.Set); } LeadRect regionBounds = RegionG.GetBounds();// _rasterImageViewer.Image.GetRegionBounds(null); LeadRectD regionRect = new LeadRectD(regionBounds.X, regionBounds.Y, regionBounds.Width, regionBounds.Height); regionRect = _rasterImageViewer.ImageTransform.TransformRect(regionRect); regionRect.Inflate(1, 1); LeadRectD imageRect = new LeadRectD(0, 0, image.ImageWidth, image.ImageHeight); imageRect = _rasterImageViewer.ImageTransform.TransformRect(imageRect); imageRect.Inflate(1, 1); using (Region region = new Region(new Rectangle((int)imageRect.X, (int)imageRect.Y, (int)imageRect.Width, (int)imageRect.Height))) { region.Exclude(new Rectangle((int)regionRect.X, (int)regionRect.Y, (int)regionRect.Width, (int)regionRect.Height)); using (Brush brush = new HatchBrush(HatchStyle.SmallConfetti, Color.Black, Color.FromArgb(64, Color.Black))) { e.PaintEventArgs.Graphics.FillRegion(brush, region); } } e.PaintEventArgs.Graphics.DrawRectangle(Pens.Black, (int)regionRect.X, (int)regionRect.Y, (int)regionRect.Width, (int)regionRect.Height); e.PaintEventArgs.Graphics.DrawRectangle(Pens.Black, (int)imageRect.X, (int)imageRect.Y, (int)imageRect.Width, (int)imageRect.Height); } } }
public override void Render(AnnContainerMapper mapper, AnnObject annObject) { if (mapper == null) { ExceptionHelper.ArgumentNullException("mapper"); } if (annObject == null) { ExceptionHelper.ArgumentNullException("annObject"); } base.Render(mapper, annObject); AnnRichTextObject annRichTextObject = annObject as AnnRichTextObject; if (annRichTextObject != null && !String.IsNullOrEmpty(annRichTextObject.Rtf)) { AnnWinFormsRenderingEngine engine = RenderingEngine as AnnWinFormsRenderingEngine; if (engine != null && engine.Context != null) { AnnRectangleObject tempRect = new AnnRectangleObject(); tempRect.Points.Clear(); foreach (LeadPointD pt in GetRenderPoints(mapper, annRichTextObject)) { tempRect.Points.Add(pt); } double rotation = tempRect.Angle; if (rotation == 180) { rotation = 0; } LeadRectD boundsPixels = tempRect.Rect.Clone(); AnnContainerMapper identityMapper = mapper.Clone(); identityMapper.UpdateTransform(LeadMatrix.Identity); identityMapper.MapResolutions(mapper.SourceDpiX, mapper.SourceDpiY, mapper.SourceDpiX, mapper.SourceDpiY); boundsPixels = identityMapper.RectFromContainerCoordinates(boundsPixels, annRichTextObject.FixedStateOperations); if (tempRect.Stroke != null) { boundsPixels.Inflate(-tempRect.Stroke.StrokeThickness.Value, -tempRect.Stroke.StrokeThickness.Value); } string rtf = annRichTextObject.Rtf; IntPtr hemfDC; if (_richTextBox == null) { _richTextBox = new InternalRichTextEdit(); } try { _richTextBox.Rtf = rtf; } catch { using (RichTextBox richTextBox = new RichTextBox()) { richTextBox.Text = rtf; annRichTextObject.Rtf = richTextBox.Rtf; _richTextBox.Rtf = richTextBox.Rtf; } } Graphics graphics = engine.Context; double dpiX = 96; double dpiY = 96; _richTextBox.Location = new Point((int)boundsPixels.Location.X, (int)boundsPixels.Location.Y); _richTextBox.Size = new Size((int)boundsPixels.Size.Width, (int)boundsPixels.Size.Height); IntPtr hdc = graphics.GetHdc(); Win32.RECT rc = new Win32.RECT(); rc.left = _richTextBox.ClientRectangle.Left; rc.top = _richTextBox.ClientRectangle.Top; rc.right = (int)boundsPixels.Width; rc.bottom = (int)boundsPixels.Height; int iWidthMM = SafeNativeMethods.GetDeviceCaps(hdc, Win32.HORZSIZE); int iHeightMM = SafeNativeMethods.GetDeviceCaps(hdc, Win32.VERTSIZE); int iWidthPels = SafeNativeMethods.GetDeviceCaps(hdc, Win32.HORZRES); int iHeightPels = SafeNativeMethods.GetDeviceCaps(hdc, Win32.VERTRES); rc.left = (rc.left * iWidthMM * 100) / iWidthPels; rc.top = (rc.top * iHeightMM * 100) / iHeightPels; rc.right = (rc.right * iWidthMM * 100) / iWidthPels; rc.bottom = (rc.bottom * iHeightMM * 100) / iHeightPels; hemfDC = SafeNativeMethods.CreateEnhMetaFile(hdc, null, ref rc, null); Win32.RECT emfRect = new Win32.RECT(); emfRect.right = (int)boundsPixels.Width; emfRect.bottom = (int)boundsPixels.Height; IntPtr brush = SafeNativeMethods.GetStockObject(5); SafeNativeMethods.SetBkMode(hemfDC, 1); SafeNativeMethods.FillRect(hemfDC, ref emfRect, brush); SafeNativeMethods.DeleteObject(brush); Print(_richTextBox, _richTextBox.ClientRectangle, hemfDC, (int)dpiX, (int)dpiY, false); IntPtr hemf = SafeNativeMethods.CloseEnhMetaFile(hemfDC); using (Metafile metaFile = new Metafile(hemf, true)) { graphics.ReleaseHdc(); GraphicsState state = graphics.Save(); //the mapper transform dosent contain dpi effect so we will add dpi effect . LeadMatrix matrix = mapper.Transform; //add dpi effect to the transform matrix.Scale((float)(mapper.TargetDpiX / mapper.SourceDpiX), (float)(mapper.TargetDpiY / mapper.SourceDpiY)); if ((annRichTextObject.FixedStateOperations & AnnFixedStateOperations.Scrolling) == AnnFixedStateOperations.Scrolling) { matrix.Translate(-matrix.OffsetX, -matrix.OffsetY); } if ((annRichTextObject.FixedStateOperations & AnnFixedStateOperations.Zooming) == AnnFixedStateOperations.Zooming) { double offsetX = matrix.OffsetX; double offsetY = matrix.OffsetY; double scaleX = 1.0; double scaleY = 1.0; if (matrix.M11 != 0 && matrix.M22 != 0) { scaleX = 1.0 / Math.Abs(matrix.M11); scaleY = 1.0 / Math.Abs(matrix.M22); } matrix.Scale(scaleX, scaleY); } using (Matrix transform = new Matrix((float)matrix.M11, (float)matrix.M12, (float)matrix.M21, (float)matrix.M22, (float)matrix.OffsetX, (float)matrix.OffsetY)) { graphics.MultiplyTransform(transform); graphics.DrawImage(metaFile, new Point((int)boundsPixels.Left, (int)boundsPixels.Top)); } graphics.Restore(state); } } //EndDraw(graphics, gState); } }