本文整理汇总了C#中System.Windows.Rect.Scale方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.Scale方法的具体用法?C# Rect.Scale怎么用?C# Rect.Scale使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Rect
的用法示例。
在下文中一共展示了Rect.Scale方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OffsetRect
public static Rect OffsetRect(Rect rect, Vector offset, double scale)
{
Rect result = new Rect(rect.TopLeft, rect.BottomRight);
result.Offset(offset);
result.Scale(scale, scale);
return result;
}
示例2: ScaleRect
partial static void ScaleRect(ref Rect rect, ref Transform transform)
{
// Scales the RectangleGeometry to compensate inaccurate hit testing in WPF.
// See http://stackoverflow.com/a/19335624/1136211
rect.Scale(1e6, 1e6);
var scaleTransform = new ScaleTransform(1e-6, 1e-6); // reverts rect scaling
scaleTransform.Freeze();
var transformGroup = new TransformGroup();
transformGroup.Children.Add(scaleTransform);
transformGroup.Children.Add(transform);
transform = transformGroup;
}
示例3: GetViewerBounds
Rect GetViewerBounds()
{
ScrollViewer parentView = this.DesignerView.ScrollViewer;
Rect viewerBounds = new Rect(parentView.HorizontalOffset, parentView.VerticalOffset, parentView.ViewportWidth, parentView.ViewportHeight);
viewerBounds.Scale(1 / this.designerView.ZoomFactor, 1 / this.designerView.ZoomFactor);
return viewerBounds;
}
示例4: ContentToPixel
public List<ContentLocation> ContentToPixel(String wordToSearch, int actualPage, double width, double height)
{
List<ContentLocation> results = new List<ContentLocation>();
if (wordToSearch == null || wordToSearch.Length == 0)
return results;
using (FileStream fileIn = new FileStream(DocumentPath, FileMode.Open, FileAccess.Read))
{
//0- Open and load the PDF
Document PdfDocument = new Document(fileIn);
for (int pageIndex = 0; pageIndex < PdfDocument.Pages.Count; pageIndex++)
{
// searches only on the actual page, or on all of them if actualPage == -1
if (actualPage != -1 && actualPage != pageIndex)
continue;
//1- try to find the piece of content the mouse is hovering
TallComponents.PDF.Page page = PdfDocument.Pages[pageIndex];
double widthT = width / page.Width;
double heightT = height / page.Height;
//retrieve all glyphs from the current page
//Notice that you grep a strong reference to the glyphs, otherwise the GC can decide to recycle.
GlyphCollection glyphs = page.Glyphs;
//default the glyph collection is ordered as they are present in the PDF file.
//we want them in reading order.
glyphs.Sort();
//the bounds of the last glyph analysed
Rect glyphBounds = Rect.Empty;
//the current word over which the user clicked
StringBuilder currentWord = new StringBuilder();
Rect wordBounds = Rect.Empty;
bool foundWord = false;
int wordIndex = 0;
foreach (TallComponents.PDF.TextExtraction.Glyph glyph in glyphs)
{
if (glyph.Characters.Length == 0 || wordIndex == 0)
{
if (foundWord)
{
double wordWidth = glyphBounds.Right - wordBounds.Left;
if (wordWidth > 0) //multi-line word -- the bounds cover only the upper part of it
wordBounds = new Rect(wordBounds.Left, wordBounds.Top, wordWidth, wordBounds.Height);
foundWord = false;
results.Add(new ContentLocation() { Content = currentWord.ToString(), PageIndex = pageIndex, ContentBounds = wordBounds });
}
wordIndex = 0;
wordBounds = Rect.Empty;
currentWord.Clear();
//continue;
}
glyphBounds = new Rect(
glyph.TopLeft.X,
page.Height - glyph.TopLeft.Y,
glyph.TopRight.X - glyph.TopLeft.X,
glyph.TopLeft.Y - glyph.BottomLeft.Y);
glyphBounds.Scale(widthT, heightT);
if (wordBounds == Rect.Empty)
wordBounds = glyphBounds;
string chars = String.Empty;
foreach (char ch in glyph.Characters)
currentWord.Append(ch);
if (!wordToSearch[wordIndex].ToString().Equals(glyph.Characters[0].ToString(), StringComparison.CurrentCultureIgnoreCase))
wordIndex = 0;
else wordIndex++;
if (wordIndex == wordToSearch.Length)
{
foundWord = true;
wordIndex = 0;
}
}
}
}
return results;
}
示例5: PixelToContent
public string PixelToContent(Point position, int actualPage, double width, double height, out Rect wordBounds)
{
using (FileStream fileIn = new FileStream(DocumentPath, FileMode.Open, FileAccess.Read))
{
//0- Open and load the PDF
Document PdfDocument = new Document(fileIn);
//1- try to find the piece of content the mouse is hovering
TallComponents.PDF.Page page = PdfDocument.Pages[actualPage];
double widthT = width / page.Width;
double heightT = height / page.Height;
//retrieve all glyphs from the current page
//Notice that you grep a strong reference to the glyphs, otherwise the GC can decide to recycle.
GlyphCollection glyphs = page.Glyphs;
//default the glyph collection is ordered as they are present in the PDF file.
//we want them in reading order.
glyphs.Sort();
//the bounds of the last glyph analysed
Rect glyphBounds = Rect.Empty;
//the current word over which the user clicked
StringBuilder currentWord = new StringBuilder();
wordBounds = Rect.Empty;
bool foundWord = false;
foreach (TallComponents.PDF.TextExtraction.Glyph glyph in glyphs)
{
if (glyph.Characters.Length == 0 || glyph.Characters[0] == ' ')
{
if (foundWord)
{
double wordWidth = glyphBounds.Right - wordBounds.Left;
if (wordWidth > 0) //multi-line word -- the bounds cover only the upper part of it
wordBounds = new Rect(wordBounds.Left, wordBounds.Top, wordWidth, wordBounds.Height);
return currentWord.ToString();
}
wordBounds = Rect.Empty;
currentWord.Clear();
continue;
}
glyphBounds = new Rect(
glyph.TopLeft.X,
page.Height - glyph.TopLeft.Y,
glyph.TopRight.X - glyph.TopLeft.X,
glyph.TopLeft.Y - glyph.BottomLeft.Y);
glyphBounds.Scale(widthT, heightT);
if (wordBounds == Rect.Empty)
wordBounds = glyphBounds;
string chars = String.Empty;
foreach (char ch in glyph.Characters)
currentWord.Append(ch);
if (!glyphBounds.Contains(position))
continue;
foundWord = true;
//Console.WriteLine("{0} -[{1},{2},{3},{4}] Font={5}({6})", chars, glyph.BottomLeft,
// glyph.BottomRight, glyph.TopLeft, glyph.TopRight, glyph.Font.Name, glyph.FontSize);
}
return null;
}
}
示例6: CalculateViewport
public void CalculateViewport()
{
Rect actualView = new Rect(0, 0, this.ActualWidth, this.ActualHeight);
actualView.Scale(1 / Scale, 1 / Scale);
actualView.Offset(-this.XViewOffset, -this.YViewOffset);
_viewport = actualView;
}
示例7: OnPropertyChanged
protected override void OnPropertyChanged(PropertyNotificationEventArgs args)
{
if (args.PropertyName.Equals("Width") || args.PropertyName.Equals("Height"))
{
double scaleX = Width / NativeSize.Width;
double scaleY = Height / NativeSize.Height;
_guardUpRegion = GuardedToggleSwitch.GuardUpRegion;
_guardUpRegion.Scale(scaleX, scaleY);
_switchRegion = GuardedToggleSwitch.SwitchRegion;
_switchRegion.Scale(scaleX, scaleY);
_guardDownRegion = GuardedToggleSwitch.GuardDownRegion;
_guardDownRegion.Scale(scaleX, scaleY);
}
base.OnPropertyChanged(args);
}
示例8: TransformRect
internal override void TransformRect(ref Rect rect)
{
if (rect.IsEmpty)
{
return;
}
double scaleX = ScaleX;
double scaleY = ScaleY;
double centerX = CenterX;
double centerY = CenterY;
bool translateCenter = centerX != 0 || centerY != 0;
if (translateCenter)
{
rect.X -= centerX;
rect.Y -= centerY;
}
rect.Scale(scaleX, scaleY);
if (translateCenter)
{
rect.X += centerX;
rect.Y += centerY;
}
}
示例9: OnRender
protected override void OnRender(DrawingContext dc)
{
//warning : много хаков!
if (_diagram == null)
return;
Rect actualViewport = new Rect(0, 0, ActualWidth, ActualHeight);
dc.DrawRectangle(Brushes.White, null, actualViewport);
Rect boundaries = _diagram.Boundaries;
Rect viewport = _diagram.Viewport;
double scale;
double scaleX = actualViewport.Width / boundaries.Width;
double scaleY = actualViewport.Height / boundaries.Height;
scale = scaleX > scaleY ? scaleY : scaleX;
//прямоугольник с элементами
Rect viewerBoundaries = new Rect(0, 0, boundaries.Width * scale, boundaries.Height * scale);
dc.DrawRectangle(Brushes.White, GlobalData.BorderPen, viewerBoundaries);
//вьюпорт
Vector offset = new Vector(-boundaries.Left, -boundaries.Top);
Rect viewerViewport = new Rect(viewport.TopLeft, viewport.BottomRight);
viewerViewport.Offset(offset.X , offset.Y);
viewerViewport.Scale(scale, scale);
//пересекаем
RectangleGeometry geometryBoundaries = new RectangleGeometry(viewerBoundaries);
RectangleGeometry geometryViewport = new RectangleGeometry(viewerViewport);
CombinedGeometry geometryCombined = new CombinedGeometry(GeometryCombineMode.Exclude,
geometryBoundaries, geometryViewport);
SolidColorBrush brush = new SolidColorBrush(Colors.LightGray);
dc.PushOpacity(0.3);
dc.DrawGeometry(brush, null, geometryCombined);
dc.Pop();
dc.PushTransform(new ScaleTransform(scale, scale));
dc.PushTransform(new TranslateTransform(offset.X, offset.Y));
_diagram.DrawItems(dc);
dc.Pop();
dc.Pop();
}
示例10: MakeVisible
/// <summary>
/// Forces content to scroll until the coordinate space of a <see cref="T:System.Windows.Media.Visual" /> object is visible.
/// </summary>
/// <param name="visual">A <see cref="T:System.Windows.Media.Visual" /> that becomes visible.</param>
/// <param name="rectangle">A bounding rectangle that identifies the coordinate space to make visible.</param>
/// <returns>A <see cref="T:System.Windows.Rect" /> that is visible.</returns>
public Rect MakeVisible(Visual visual, Rect rectangle)
{
if (rectangle.IsEmpty || visual == null
|| visual == this || !base.IsAncestorOf(visual))
{ return Rect.Empty; }
rectangle = visual.TransformToAncestor(this).TransformBounds(rectangle);
//rectangle.Inflate(50, 50);
rectangle.Scale(1.2, 1.2);
Rect viewRect = new Rect(HorizontalOffset,
VerticalOffset, ViewportWidth, ViewportHeight);
rectangle.X += viewRect.X;
rectangle.Y += viewRect.Y;
viewRect.X = CalculateNewScrollOffset(viewRect.Left,
viewRect.Right, rectangle.Left, rectangle.Right);
viewRect.Y = CalculateNewScrollOffset(viewRect.Top,
viewRect.Bottom, rectangle.Top, rectangle.Bottom);
SetHorizontalOffset(viewRect.X);
SetVerticalOffset(viewRect.Y);
rectangle.Intersect(viewRect);
rectangle.X -= viewRect.X;
rectangle.Y -= viewRect.Y;
return rectangle;
}
示例11: Fill
internal static Arc Fill(Size availableSize, double start, double end)
{
if (availableSize.Width == 0 ||
double.IsNaN(availableSize.Width) ||
availableSize.Height == 0 ||
double.IsNaN(availableSize.Height))
{
return new Arc(new Point(0, 0), start, end, 0, false);
}
var p0 = new Point(0, 0);
var arc = new Arc(p0, start, end, 1, false);
var rect = new Rect();
var ps = arc.GetPoint(start);
rect.Union(ps);
rect.Union(arc.GetPoint(end));
foreach (var quadrant in arc.GetQuadrants(start, end))
{
rect.Union(quadrant);
}
var wf = availableSize.Width / rect.Width;
var hf = availableSize.Height / rect.Height;
var r = Math.Min(wf, hf);
rect.Scale(r, r);
var v = rect.FindTranslationToCenter(availableSize);
return new Arc(p0 + v, start, end, r, false);
}