public static bool CompareByValue(this ColorBlend blend1, ColorBlend blend2) { if (blend1 == null || blend2 == null) { return(false); } if (blend1.Colors.Count() != blend2.Colors.Count() || blend1.Positions.Count() != blend2.Positions.Count()) { return(false); } for (int i = 0; i < blend1.Colors.Count(); i++) { if (blend1.Colors[i] != blend2.Colors[i]) { return(false); } } for (int i = 0; i < blend1.Positions.Count(); i++) { if (!NumericHelper.Equal(blend1.Positions[i], blend2.Positions[i])) { return(false); } } return(true); }
/// <summary> /// Recursively calculates new extents of the map ot cover a certain geo size in meters. /// </summary> private static IEnvelope CalcNewExtentsCore( IPrintableMap map, IEnvelope oldExtents, GeoSize newSize, SizeF paperSize, ref int depth) { depth++; GeoSize oldSize; if (map.GetGeodesicSize(oldExtents, out oldSize)) { const int maxDepth = 5; double newScale = CalcMapScale(newSize, paperSize); double oldScale = CalcMapScale(oldSize, paperSize); if (NumericHelper.Equal(newScale, oldScale, 1e-6) || depth > maxDepth) { return(oldExtents); } double ratio = newScale / oldScale - 1; double dx = oldExtents.Width * ratio; double dy = oldExtents.Height * ratio; var extents = oldExtents.Inflate(dx, dy); return(CalcNewExtentsCore(map, extents, newSize, paperSize, ref depth)); } return(null); }
protected override void OnSizeChanged() { base.OnSizeChanged(); if (Envelope == null) { _oldRectangle = Rectangle; return; } if (Resizing) { return; } if (!NumericHelper.Equal(_oldRectangle.Width, 0.0) && !NumericHelper.Equal(_oldRectangle.Height, 0.0)) { double dx = _oldRectangle.Width / Envelope.Width; double dy = _oldRectangle.Height / Envelope.Height; var newEnv = Envelope.Clone(); double plusX = (Rectangle.Width - _oldRectangle.Width) / dx; double plusY = (Rectangle.Height - _oldRectangle.Height) / dy; newEnv.SetBounds(newEnv.MinX, newEnv.MaxX + plusX, newEnv.MinY - plusY, newEnv.MaxY); Envelope = newEnv; } _oldRectangle = Rectangle; }
public static IEnvelope SetBoundsWithXYRatio(IEnvelope bounds, SizeF ratio) { if (NumericHelper.Equal(ratio.Width, 0.0) || NumericHelper.Equal(ratio.Height, 0.0)) { return(bounds.Clone()); } double height = bounds.Height; double width = bounds.Width; if (ratio.Height / ratio.Width > height / width) { height = ratio.Height * width / ratio.Width; } else { width = ratio.Width * height / ratio.Height; } var result = new Envelope(); result.SetBounds(bounds.Center, width, height); return(result); }
/// <summary> /// Adjusts font size for the case when screen DPI is different from the default. /// </summary> private void AdjustFonts(bool export) { if (export && NumericHelper.Equal(ScreenHelper.ScreenDpi, 100f)) { _font = new Font(_font.FontFamily, _font.Size / ScreenHelper.ScreenDpi * 100f); _font2 = new Font(_font2.FontFamily, _font2.Size / ScreenHelper.ScreenDpi * 100f); } }
/// <summary> /// Calculates canvas size in pixels. /// </summary> private bool CalculateCanvasSize(out SizeF size) { size = default(SizeF); var extents = View.MapExtents; GeoSize geoSize; if (!_context.Map.GetGeodesicSize(extents, out geoSize)) { return(false); } if (!NumericHelper.Equal(View.MapScale, 0.0)) { size = LayoutScaleHelper.CalcMapSize(View.MapScale, geoSize, extents.Width / extents.Height); } return(true); }
public void Initialize(IGeometryMarkerStyle markerStyle) { if (markerStyle == null) { throw new ArgumentNullException("markerStyle"); } _marker = markerStyle; FillCollectionCombo(); chkScaleIcons.Checked = !NumericHelper.Equal(_marker.IconScaleX, 1.0) || !NumericHelper.Equal(_marker.IconScaleY, 1.0); iconControl1.SelectionChanged += FireSelectedIconChanged; chkScaleIcons.CheckStateChanged += (s, e) => FireScaleChanged(); cboIconCollection.SelectedIndexChanged += (s, e) => UpdateIconsList(); RestoreSelectedIconCollection(); }
/// <summary> /// Calculates the size of the map on screen for a given size of map area and scale. /// </summary> /// <param name="mapScale">Map scale.</param> /// <param name="geoSize">Geodesic size of the map area in meters.</param> /// <param name="xyRatio">The X / Y ratio for the extents in original coordinate system.</param> /// <returns>Size of the map on the screen in 1/100 of an inch.</returns> public static SizeF CalcMapSize(int mapScale, GeoSize geoSize, double xyRatio) { double cf = LengthUnits.Meters.GetConversionFactor(); var widthInches = geoSize.Width * cf / mapScale; var heightInches = geoSize.Height * cf / mapScale; // The distortion introduced be orginal map coordinate system may be different along X and Y axes, // so paper size rectangle may no longer have the same X / Y side ratio as original extents. // This will result in adjustment of extents in map projection according to this ratio, which is undesirable. // Let's instead adjust resulting paper size to orignal X / Y ratio. double newRatio = widthInches / heightInches; if (!NumericHelper.Equal(newRatio, xyRatio, 1e-6)) { double correction = Math.Sqrt(newRatio / xyRatio); heightInches *= correction; widthInches /= correction; } return(new SizeF((float)(widthInches * 100.0), (float)(heightInches * 100.0))); }
private void AdjustMinRectSize(ref RectangleF value) { if (value.Width < 10) { value.Width = 10; if (!NumericHelper.Equal(value.X, _location.X)) { value.X = _location.X + _size.Width - 10; } } if (value.Height < 10) { value.Height = 10; if (!NumericHelper.Equal(value.Y, _location.Y)) { value.Y = _location.Y + _size.Height - 10; } } }
protected override void UpdateThumbnail() { if (Resizing || NumericHelper.Equal(SizeF.Width, 0.0) || NumericHelper.Equal(SizeF.Height, 0.0)) { return; } var tempThumbnail = new Bitmap(32, 32, PixelFormat.Format32bppArgb); using (var g = Graphics.FromImage(tempThumbnail)) { g.SmoothingMode = SmoothingMode.AntiAlias; g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; if (_buffer != null) { g.DrawImage(_buffer, new RectangleF(0.0f, 0.0f, 32.0f, 32.0f)); } } Thumbnail = tempThumbnail; }
private void ResizeSelected(float deltaX, float deltaY) { if (NumericHelper.Equal(deltaX, 0f) && NumericHelper.Equal(deltaY, 0f)) { return; } _suppressElementInvalidation = true; var el = _selectedLayoutElements[0]; var oldScreenRect = PaperToScreen(el.Rectangle); AdjustRectangle(ref oldScreenRect, deltaX, deltaY); el.Rectangle = ScreenToPaper(oldScreenRect); DoInvalidate(); Update(); _suppressElementInvalidation = false; }
/// <summary> /// Drawing code /// </summary> protected override void Draw(Graphics g, bool printing, bool export, int x, int y) { if (_layoutMap == null || _layoutMap.Scale == 0) { return; } var font = Font; double geoBreakWidth = GetGeoBreakWidth(g, font); if (NumericHelper.Equal(geoBreakWidth, 0.0) || Double.IsNaN(geoBreakWidth)) { g.DrawString(@"#Scale Error#", font, Brushes.Black, x, y); return; } int breakWidth = GetBreakScreenWidth(geoBreakWidth); var fontSize = MeasureString(g, geoBreakWidth, font); float leftStart = fontSize.Width / 2F; StartDrawing(g, x, y); try { Brush scaleBrush = new SolidBrush(_color); var scalePen = new Pen(scaleBrush); float yCenter = fontSize.Height * 1.6f; float yTop = fontSize.Height * 1.1f; int startBreak = _breakBeforeZero ? -1 : 0; // horizontal line g.DrawLine(scalePen, leftStart, yCenter, leftStart + (breakWidth * _numBreaks), yCenter); // displaying scale at bottom left if (ShowScale) { var width = MeasureString(g, geoBreakWidth * startBreak, font).Width / 2; g.DrawString("1 : " + Map.Scale, font, scaleBrush, leftStart - width, fontSize.Height * 2.5F); } // vertical marks for (int i = startBreak; i <= _numBreaks + startBreak; i++) { g.DrawLine(scalePen, leftStart, yTop, leftStart, fontSize.Height + yTop); var width = MeasureString(g, geoBreakWidth * i, font).Width / 2f; string s = Math.Abs(geoBreakWidth * i).ToString(CultureInfo.InvariantCulture); g.DrawString(s, font, scaleBrush, leftStart - width, 0); leftStart = leftStart + breakWidth; } // units g.DrawString(UnitText, font, scaleBrush, leftStart - breakWidth + (fontSize.Height / 2f), yTop); } finally { StopDrawing(g); } }