Explore Enterprise Education Gitee Premium Gitee AI AI teammates
Fetch the repository succeeded.
Create your Gitee Account
Explore and code with more than 14 million developers,Free private repositories !:)
Sign up
Already have an account? Sign in
文件
master
Branches (17)
Tags (33)
master
sync_branch_202410
sync_branch_2023年3月14日
updatedLicenses
updatedReadme
sync_branch_2023年1月5日
sync_branch_2023年1月4日
sync_branch_2023年1月3日
Detrav-patch-2
sync_branch_202310
KirillKornienko-patch-1
Detrav-patch-1
sync_branch_202230
finalUpdatePackScript
PackScript
SomeFixesInDeterministicBuilds
AddedBuildDirToPack
v2025.2.0
v2025.1.0
v2024.2.0
v2024.1.10
v2024.1.3
v2024.1.0
v2023.3.0
v2023.2.0
v2023.1.0
v2022.3.11
v2022.3.0
v2022.2.0
v2022.1.0
v2021.4.0
v2021.3.28
v2021.3.21
v2021.3.0
v2021.2.0
2021年1月16日
v2021.1.0
master
Branches (17)
Tags (33)
master
sync_branch_202410
sync_branch_2023年3月14日
updatedLicenses
updatedReadme
sync_branch_2023年1月5日
sync_branch_2023年1月4日
sync_branch_2023年1月3日
Detrav-patch-2
sync_branch_202310
KirillKornienko-patch-1
Detrav-patch-1
sync_branch_202230
finalUpdatePackScript
PackScript
SomeFixesInDeterministicBuilds
AddedBuildDirToPack
v2025.2.0
v2025.1.0
v2024.2.0
v2024.1.10
v2024.1.3
v2024.1.0
v2023.3.0
v2023.2.0
v2023.1.0
v2022.3.11
v2022.3.0
v2022.2.0
v2022.1.0
v2021.4.0
v2021.3.28
v2021.3.21
v2021.3.0
v2021.2.0
2021年1月16日
v2021.1.0
Clone or Download
Clone/Download
Prompt
To download the code, please copy the following command and execute it in the terminal
To ensure that your submitted code identity is correctly recognized by Gitee, please execute the following command.
When using the SSH protocol for the first time to clone or push code, follow the prompts below to complete the SSH configuration.
1 Generate RSA keys.
2 Obtain the content of the RSA public key and configure it in SSH Public Keys
To use SVN on Gitee, please visit the usage guide
When using the HTTPS protocol, the command line will prompt for account and password verification as follows. For security reasons, Gitee recommends configure and use personal access tokens instead of login passwords for cloning, pushing, and other operations.
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # Private Token
master
Branches (17)
Tags (33)
master
sync_branch_202410
sync_branch_2023年3月14日
updatedLicenses
updatedReadme
sync_branch_2023年1月5日
sync_branch_2023年1月4日
sync_branch_2023年1月3日
Detrav-patch-2
sync_branch_202310
KirillKornienko-patch-1
Detrav-patch-1
sync_branch_202230
finalUpdatePackScript
PackScript
SomeFixesInDeterministicBuilds
AddedBuildDirToPack
v2025.2.0
v2025.1.0
v2024.2.0
v2024.1.10
v2024.1.3
v2024.1.0
v2023.3.0
v2023.2.0
v2023.1.0
v2022.3.11
v2022.3.0
v2022.2.0
v2022.1.0
v2021.4.0
v2021.3.28
v2021.3.21
v2021.3.0
v2021.2.0
2021年1月16日
v2021.1.0
FastReport
/
FastReport.Base
/
PictureObjectBase.cs
FastReport
/
FastReport.Base
/
PictureObjectBase.cs
PictureObjectBase.cs 32.68 KB
Copy Edit Raw Blame History
FastReports-bot authored 2024年10月16日 21:13 +08:00 . * sync 10/16/2024 version: 202510
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.IO;
using System.Windows.Forms;
using FastReport.Utils;
namespace FastReport
{
/// <summary>
/// Specifies the alignment of a image in the border.
/// </summary>
public enum ImageAlign
{
/// <summary>
/// Specifies that image is not aligned in the layout rectangle.
/// </summary>
None,
/// <summary>
/// Specifies that image is aligned in the top-left of the layout rectangle.
/// </summary>
Top_Left,
/// <summary>
/// Specifies that image is aligned in the top-center of the layout rectangle.
/// </summary>
Top_Center,
/// <summary>
/// Specifies that image is aligned in the top-right of the layout rectangle.
/// </summary>
Top_Right,
/// <summary>
/// Specifies that image is aligned in the center-left of the layout rectangle.
/// </summary>
Center_Left,
/// <summary>
/// Specifies that image is aligned in the center-center of the layout rectangle.
/// </summary>
Center_Center,
/// <summary>
/// Specifies that image is aligned in the center-right of the layout rectangle.
/// </summary>
Center_Right,
/// <summary>
/// Specifies that image is aligned in the center-left of the layout rectangle.
/// </summary>
Bottom_Left,
/// <summary>
/// Specifies that image is aligned in the center-center of the layout rectangle.
/// </summary>
Bottom_Center,
/// <summary>
/// Specifies that image is aligned in the center-right of the layout rectangle.
/// </summary>
Bottom_Right,
}
/// <summary>
/// the base class for all picture objects
/// </summary>
public abstract partial class PictureObjectBase : ReportComponentBase
{
#region Internal Fields
#endregion Internal Fields
#region Private Fields
private int angle;
private string dataColumn;
private bool grayscale;
private string imageLocation;
private string imageSourceExpression;
private float maxHeight;
private float maxWidth;
private Padding padding;
private PictureBoxSizeMode saveSizeMode;
private bool showErrorImage;
private PictureBoxSizeMode sizeModeInternal;
private ImageAlign imageAlign;
private ShapeKind shape;
#endregion Private Fields
#region Public Properties
/// <summary>
/// Gets or sets the image rotation angle, in degrees. Possible values are 0, 90, 180, 270.
/// </summary>
[DefaultValue(0)]
[Category("Appearance")]
public int Angle
{
get { return angle; }
set { angle = value; }
}
/// <summary>
/// Gets or sets the data column name to get the image from.
/// </summary>
[Category("Data")]
[Editor("FastReport.TypeEditors.DataColumnEditor, FastReport", typeof(UITypeEditor))]
public string DataColumn
{
get { return dataColumn; }
set { dataColumn = value; }
}
/// <summary>
/// Gets or sets a value indicating that the image should be displayed in grayscale mode.
/// </summary>
[DefaultValue(false)]
[Category("Appearance")]
public virtual bool Grayscale
{
get { return grayscale; }
set
{
grayscale = value;
}
}
/// <inheritdoc/>
public override float Height
{
get { return base.Height; }
set
{
if (MaxHeight != 0 && value > MaxHeight)
value = MaxHeight;
base.Height = value;
}
}
/// <summary>
/// Gets or sets the path for the image to display in the PictureObject.
/// </summary>
/// <remarks>
/// This property may contain the path to the image file as well as external URL.
/// </remarks>
[Category("Data")]
public string ImageLocation
{
get { return imageLocation; }
set
{
SetImageLocation(value, true); // or IsDesigning
}
}
/// <summary>
/// Gets or sets the expression that determines the source for the image to display in the PictureObject.
/// </summary>
/// <remarks>
/// The result of the expression should be data column name or path to the image file.
/// The data column name will be saved to the <see cref="DataColumn"/> property.
/// The path will be savetd to the <see cref="ImageLocation"/> property.
/// </remarks>
[Category("Data")]
[Editor("FastReport.TypeEditors.ExpressionEditor, FastReport", typeof(UITypeEditor))]
public string ImageSourceExpression
{
get { return imageSourceExpression; }
set
{
imageSourceExpression = value;
if (!String.IsNullOrEmpty(ImageSourceExpression) && Report != null)
{
string expression = ImageSourceExpression;
if (ImageSourceExpression.StartsWith("[") && ImageSourceExpression.EndsWith("]"))
{
expression = ImageSourceExpression.Substring(1, ImageSourceExpression.Length - 2);
}
if (Data.DataHelper.IsValidColumn(Report.Dictionary, expression))
{
DataColumn = expression;
}
if (Data.DataHelper.IsValidParameter(Report.Dictionary, expression))
{
ImageLocation = Report.GetParameterValue(expression).ToString();
}
}
}
}
/// <summary>
/// Gets a value indicating that the image stored in the databases column
/// </summary>
[Browsable(false)]
public bool IsDataColumn
{
get { return !String.IsNullOrEmpty(DataColumn); }
}
/// <summary>
/// Gets a value indicating that the image stored in the separate file
/// </summary>
[Browsable(false)]
public bool IsFileLocation
{
get
{
if (String.IsNullOrEmpty(ImageLocation))
return false;
Uri uri = CalculateUri();
return uri.IsFile;
}
}
/// <summary>
/// Gets a value indicating that the image stored in the Web
/// </summary>
[Browsable(false)]
public bool IsWebLocation
{
get
{
if (String.IsNullOrEmpty(ImageLocation))
return false;
Uri uri = CalculateUri();
return !uri.IsFile;
}
}
/// <summary>
/// Gets or sets the maximum height of a Picture object, in pixels.
/// </summary>
/// <remarks>
/// Use this property to restrict the object size if the <see cref="SizeMode"/> property
/// is set to <b>AutoSize</b>.
/// </remarks>
[DefaultValue(0f)]
[Category("Layout")]
[TypeConverter("FastReport.TypeConverters.UnitsConverter, FastReport")]
public float MaxHeight
{
get { return maxHeight; }
set { maxHeight = value; }
}
/// <summary>
/// Gets or sets the maximum width of a Picture object, in pixels.
/// </summary>
/// <remarks>
/// Use this property to restrict the object size if the <see cref="SizeMode"/> property
/// is set to <b>AutoSize</b>.
/// </remarks>
[DefaultValue(0f)]
[Category("Layout")]
[TypeConverter("FastReport.TypeConverters.UnitsConverter, FastReport")]
public float MaxWidth
{
get { return maxWidth; }
set { maxWidth = value; }
}
/// <summary>
/// Gets or sets padding within the PictureObject.
/// </summary>
[Category("Layout")]
public Padding Padding
{
get { return padding; }
set { padding = value; }
}
/// <summary>
/// Gets or sets a value indicating whether the PictureObject should display
/// the error indicator if there is no image in it.
/// </summary>
[DefaultValue(false)]
[Category("Behavior")]
public bool ShowErrorImage
{
get { return showErrorImage; }
set { showErrorImage = value; }
}
/// <summary>
/// Gets or sets a value that specifies how an image is positioned within a PictureObject.
/// </summary>
[DefaultValue(PictureBoxSizeMode.Zoom)]
[Category("Behavior")]
public virtual PictureBoxSizeMode SizeMode
{
get { return sizeModeInternal; }
set
{
sizeModeInternal = value;
UpdateAutoSize();
}
}
/// <inheritdoc/>
public override float Width
{
get { return base.Width; }
set
{
if (MaxWidth != 0 && value > MaxWidth)
value = MaxWidth;
base.Width = value;
}
}
/// <summary>
/// Gets or sets the alignment of a image in the border.
/// </summary>
[DefaultValue(ImageAlign.None)]
[Category("Appearance")]
public ImageAlign ImageAlign
{
get { return imageAlign; }
set { imageAlign = value; }
}
/// <summary>
/// Gets or sets a shape kind.
/// </summary>
[DefaultValue(ShapeKind.Rectangle)]
[Category("Appearance")]
public ShapeKind Shape
{
get { return shape; }
set { shape = value; }
}
#endregion Public Properties
#region Protected Properties
/// <summary>
/// Return base size of image, internal use only
/// </summary>
[Browsable(false)]
protected abstract float ImageHeight { get; }
/// <summary>
/// Return base size of image, internal use only
/// </summary>
[Browsable(false)]
protected abstract float ImageWidth { get; }
#endregion Protected Properties
#region Public Constructors
/// <inheritdoc/>
public PictureObjectBase()
{
sizeModeInternal = PictureBoxSizeMode.Zoom;
shape = ShapeKind.Rectangle;
padding = new Padding();
imageLocation = "";
dataColumn = "";
imageSourceExpression = "";
}
#endregion Public Constructors
#region Public Methods
/// <inheritdoc/>
public override void Assign(Base source)
{
base.Assign(source);
PictureObjectBase src = source as PictureObjectBase;
if (src != null)
{
imageLocation = src.ImageLocation;
DataColumn = src.DataColumn;
ImageSourceExpression = src.ImageSourceExpression;
Padding = src.Padding;
SizeMode = src.SizeMode;
MaxWidth = src.MaxWidth;
MaxHeight = src.MaxHeight;
Angle = src.Angle;
Grayscale = src.Grayscale;
ShowErrorImage = src.ShowErrorImage;
ImageAlign = src.ImageAlign;
Shape = src.Shape;
}
}
/// <summary>
/// Calculates URI from ImageLocation
/// </summary>
/// <returns></returns>
public Uri CalculateUri()
{
try
{
return new Uri(ImageLocation);
}
catch (UriFormatException)
{
// TODO
// the problem with linux???? PATH!!!
string path;
if (!String.IsNullOrEmpty(Config.ReportSettings.ImageLocationRoot))
path = Path.Combine(Config.ReportSettings.ImageLocationRoot, ImageLocation.Replace('/', '\\'));
else
path = Path.GetFullPath(ImageLocation);
return new Uri(path);
}
}
/// <inheritdoc/>
public override void Draw(FRPaintEventArgs e)
{
UpdateAutoSize();
base.Draw(e);
DrawImage(e);
DrawMarkers(e);
Border.Draw(e, new RectangleF(AbsLeft, AbsTop, Width, Height));
DrawDesign(e);
}
public abstract void DrawImage(FRPaintEventArgs e);
/// <summary>
/// gets points for transform this image
/// </summary>
/// <param name="drawRect">the box where to draw image</param>
/// <param name="imageWidth">image width</param>
/// <param name="imageHeight">image height</param>
/// <param name="scaleX">scale horizontal</param>
/// <param name="scaleY">scale vertical</param>
/// <param name="offsetX">offset of left</param>
/// <param name="offsetY">offset of top</param>
/// <param name="upperLeft">out start of vectors</param>
/// <param name="upperRight">out end of frist vector</param>
/// <param name="lowerLeft">out end of second vector</param>
public void GetImageAngleTransform(RectangleF drawRect, float imageWidth, float imageHeight, float scaleX, float scaleY, float offsetX, float offsetY, out PointF upperLeft, out PointF upperRight, out PointF lowerLeft)
{
RectangleF rect = drawRect;
switch (SizeMode)
{
case PictureBoxSizeMode.Normal:
case PictureBoxSizeMode.AutoSize:
rect.Width = imageWidth * scaleX;
rect.Height = imageHeight * scaleY;
if (Angle == 90 || Angle == 180)
rect.X -= rect.Width - drawRect.Width;
if (Angle == 180)
rect.Y -= rect.Height - drawRect.Height;
break;
case PictureBoxSizeMode.CenterImage:
rect.Offset((Width - imageWidth) * scaleX / 2, (Height - imageHeight) * scaleY / 2);
rect.Width = imageWidth * scaleX;
rect.Height = imageHeight * scaleY;
break;
case PictureBoxSizeMode.StretchImage:
break;
case PictureBoxSizeMode.Zoom:
/*float kx = drawRect.Width / imageWidth;
float ky = drawRect.Height / imageHeight;
if (kx < ky)
rect.Height = imageHeight * kx;
else
rect.Width = imageWidth * ky;
rect.Offset(
(Width * e.ScaleX - rect.Width) / 2,
(Height * e.ScaleY - rect.Height) / 2);*/
break;
}
float gridCompensationX = offsetX + rect.X;
gridCompensationX = (int)gridCompensationX - gridCompensationX;
float gridCompensationY = offsetY + rect.Y;
gridCompensationY = (int)gridCompensationY - gridCompensationY;
if (gridCompensationX < 0)
gridCompensationX = 1 + gridCompensationX;
if (gridCompensationY < 0)
gridCompensationY = 1 + gridCompensationY;
rect.Offset(gridCompensationX, gridCompensationY);
upperLeft = new PointF(0, 0);
upperRight = new PointF(rect.Width, 0);
lowerLeft = new PointF(0, rect.Height);
float angle = Angle;
switch (SizeMode)
{
case PictureBoxSizeMode.Normal:
{
upperLeft = MovePointOnAngle(drawRect.Location, drawRect.Size, Angle);
PointF ur = rotateVector(upperRight, angle);
PointF ll = rotateVector(lowerLeft, angle);
upperRight = PointF.Add(upperLeft, new SizeF(ur));
lowerLeft = PointF.Add(upperLeft, new SizeF(ll));
}
break;
case PictureBoxSizeMode.StretchImage:
{
upperLeft = MovePointOnAngle(drawRect.Location, drawRect.Size, Angle);
upperRight = MovePointOnAngle(
drawRect.Location,
drawRect.Size, Angle + 90);
lowerLeft = MovePointOnAngle(
drawRect.Location,
drawRect.Size, Angle + 270);
}
break;
case PictureBoxSizeMode.CenterImage:
{
PointF rotatedVector;
float w = rect.Left - (drawRect.Left + drawRect.Width / 2);
float h = rect.Top - (drawRect.Top + drawRect.Height / 2);
rotatedVector = rotateVector(new PointF(w, h), Angle);
upperLeft = new PointF(rect.Left + rotatedVector.X - w, rect.Top + rotatedVector.Y - h);
rotatedVector = rotateVector(new PointF(rect.Width, 0), Angle);
upperRight = new PointF(upperLeft.X + rotatedVector.X, upperLeft.Y + rotatedVector.Y);
rotatedVector = rotateVector(new PointF(0, rect.Height), Angle);
lowerLeft = new PointF(upperLeft.X + rotatedVector.X, upperLeft.Y + rotatedVector.Y);
}
break;
case PictureBoxSizeMode.AutoSize:
case PictureBoxSizeMode.Zoom:
{
rect = new RectangleF(0, 0, imageWidth * 100f, imageHeight * 100f);
PointF center = new PointF(drawRect.Left + drawRect.Width / 2,
drawRect.Top + drawRect.Height / 2);
PointF[] p = new PointF[4];
p[0] = new PointF(-rect.Width / 2, -rect.Height / 2);
p[1] = new PointF(rect.Width / 2, -rect.Height / 2);
p[2] = new PointF(rect.Width / 2, rect.Height / 2);
p[3] = new PointF(-rect.Width / 2, rect.Height / 2);
float scaleToMin = 1;
for (int i = 0; i < 4; i++)
p[i] = rotateVector(p[i], Angle);
for (int i = 0; i < 4; i++)
{
if (p[i].X * scaleToMin < -drawRect.Width / 2)
scaleToMin = -drawRect.Width / 2 / p[i].X;
if (p[i].X * scaleToMin > drawRect.Width / 2)
scaleToMin = drawRect.Width / 2 / p[i].X;
if (p[i].Y * scaleToMin < -drawRect.Height / 2)
scaleToMin = -drawRect.Height / 2 / p[i].Y;
if (p[i].Y * scaleToMin > drawRect.Height / 2)
scaleToMin = drawRect.Height / 2 / p[i].Y;
}
upperLeft = PointF.Add(center, new SizeF(p[0].X * scaleToMin, p[0].Y * scaleToMin));
upperRight = PointF.Add(center, new SizeF(p[1].X * scaleToMin, p[1].Y * scaleToMin));
lowerLeft = PointF.Add(center, new SizeF(p[3].X * scaleToMin, p[3].Y * scaleToMin));
}
break;
}
if (ImageAlign != ImageAlign.None)
UpdateAlign(drawRect, ref upperLeft, ref upperRight, ref lowerLeft);
/*switch (Angle)
{
case 90:
upperLeft = new PointF(rect.Right, rect.Top);
upperRight = new PointF(rect.Right, rect.Bottom);
lowerLeft = new PointF(rect.Left, rect.Top);
break;
case 180:
upperLeft = new PointF(rect.Right, rect.Bottom);
upperRight = new PointF(rect.Left, rect.Bottom);
lowerLeft = new PointF(rect.Right, rect.Top);
break;
case 270:
upperLeft = new PointF(rect.Left, rect.Bottom);
upperRight = new PointF(rect.Left, rect.Top);
lowerLeft = new PointF(rect.Right, rect.Bottom);
break;
default:
upperLeft = new PointF(rect.Left, rect.Top);
upperRight = new PointF(rect.Right, rect.Top);
lowerLeft = new PointF(rect.Left, rect.Bottom);
break;
}*/
/* default:
PointF rotatedVector;
float w = rect.Left - (drawRect.Left + drawRect.Width / 2) ;
float h = rect.Top - (drawRect.Top + drawRect.Height/2);
rotatedVector = rotateVector(new PointF(w, h), Angle);
upperLeft = new PointF(rect.Left + rotatedVector.X - w, rect.Top + rotatedVector.Y - h);
rotatedVector = rotateVector(new PointF(rect.Width, 0), Angle);
upperRight = new PointF(upperLeft.X + rotatedVector.X, upperLeft.Y + rotatedVector.Y);
rotatedVector = rotateVector(new PointF(0, rect.Height), Angle);
lowerLeft = new PointF(upperLeft.X + rotatedVector.X, upperLeft.Y + rotatedVector.Y);
break;
}*/
}
private void UpdateAlign(RectangleF drawRect, ref PointF upperLeft, ref PointF upperRight, ref PointF lowerLeft)
{
PointF lowerRight = new PointF(upperRight.X + lowerLeft.X - upperLeft.X,
upperRight.Y + lowerLeft.Y - upperLeft.Y);
float top = Math.Min(Math.Min(upperLeft.Y, Math.Min(upperRight.Y, lowerLeft.Y)), lowerRight.Y);
float botom = Math.Max(Math.Max(upperLeft.Y, Math.Max(upperRight.Y, lowerLeft.Y)), lowerRight.Y);
float height = botom - top;
float offsetY = drawRect.Y - top;
float left = Math.Min(Math.Min(upperLeft.X, Math.Min(upperRight.X, lowerLeft.X)), lowerRight.X);
float right = Math.Max(Math.Max(upperLeft.X, Math.Max(upperRight.X, lowerLeft.X)), lowerRight.X);
float width = right - left;
float offsetX = drawRect.X - left;
switch (ImageAlign)
{
case ImageAlign.Top_Left:
break;
case ImageAlign.Top_Center:
offsetX += (drawRect.Width - width) / 2;
break;
case ImageAlign.Top_Right:
offsetX += drawRect.Width - width;
break;
case ImageAlign.Center_Left:
offsetY += (drawRect.Height - height) / 2;
break;
case ImageAlign.Center_Center:
offsetX += (drawRect.Width - width) / 2;
offsetY += (drawRect.Height - height) / 2;
break;
case ImageAlign.Center_Right:
offsetX += drawRect.Width - width;
offsetY += (drawRect.Height - height) / 2;
break;
case ImageAlign.Bottom_Left:
offsetY += drawRect.Height - height;
break;
case ImageAlign.Bottom_Center:
offsetX += (drawRect.Width - width) / 2;
offsetY += drawRect.Height - height;
break;
case ImageAlign.Bottom_Right:
offsetX += drawRect.Width - width;
offsetY += drawRect.Height - height;
break;
}
upperLeft.X += offsetX;
upperRight.X += offsetX;
lowerLeft.X += offsetX;
upperLeft.Y += offsetY;
upperRight.Y += offsetY;
lowerLeft.Y += offsetY;
}
/// <summary>
/// Loads image
/// </summary>
public abstract void LoadImage();
/// <summary>
/// Moves the point on specified angle
/// </summary>
/// <param name="p"></param>
/// <param name="size"></param>
/// <param name="fangle"></param>
/// <returns></returns>
public PointF MovePointOnAngle(PointF p, SizeF size, float fangle)
{
while (fangle >= 360) fangle -= 360;
while (fangle < 0) fangle += 360;
float x, y;
if (fangle < 90)
{
x = fangle / 90f * size.Width;
y = 0;
}
else if (fangle < 180)
{
x = size.Width;
y = (fangle - 90f) / 90f * size.Height;
}
else if (fangle < 270)
{
x = size.Width - (fangle - 180f) / 90f * size.Width;
y = size.Height;
}
else
{
x = 0;
y = size.Height - (fangle - 270f) / 90f * size.Height;
}
return PointF.Add(p, new SizeF(x, y));
}
/// <inheritdoc/>
public override void RestoreState()
{
base.RestoreState();
// avoid UpdateAutoSize call, use sizeModeInternal
sizeModeInternal = saveSizeMode;
}
/// <summary>
/// Rotates vector on specified angle
/// </summary>
/// <param name="p"></param>
/// <param name="fangle"></param>
/// <returns></returns>
public PointF rotateVector(PointF p, float fangle)
{
float angle = (float)(fangle / 180.0 * Math.PI);
float ax = p.X;
float ay = p.Y;
float bx = ax * (float)Math.Cos(angle) - ay * (float)Math.Sin(angle);
float by = ax * (float)Math.Sin(angle) + ay * (float)Math.Cos(angle);
return new PointF(bx, by);
}
/// <inheritdoc/>
public override void SaveState()
{
base.SaveState();
saveSizeMode = SizeMode;
}
public override void Serialize(FRWriter writer)
{
PictureObjectBase c = writer.DiffObject as PictureObjectBase;
base.Serialize(writer);
if (writer.SerializeTo != SerializeTo.Preview
&& writer.SerializeTo != SerializeTo.SourcePages
&& ImageLocation != c.ImageLocation)
writer.WriteStr("ImageLocation", ImageLocation);
if (DataColumn != c.DataColumn)
writer.WriteStr("DataColumn", DataColumn);
if (ImageSourceExpression != c.ImageSourceExpression)
writer.WriteStr("ImageSourceExpression", ImageSourceExpression);
if (Padding != c.Padding)
writer.WriteValue("Padding", Padding);
if (SizeMode != c.SizeMode)
writer.WriteValue("SizeMode", SizeMode);
if (FloatDiff(MaxWidth, c.MaxWidth))
writer.WriteFloat("MaxWidth", MaxWidth);
if (FloatDiff(MaxHeight, c.MaxHeight))
writer.WriteFloat("MaxHeight", MaxHeight);
if (Angle != c.Angle)
writer.WriteInt("Angle", Angle);
if (Grayscale != c.Grayscale)
writer.WriteBool("Grayscale", Grayscale);
if (ShowErrorImage != c.ShowErrorImage)
writer.WriteBool("ShowErrorImage", ShowErrorImage);
if (ImageAlign != ImageAlign.None)
writer.WriteValue("ImageAlign", ImageAlign);
if (Shape != c.Shape)
writer.WriteValue("Shape", Shape);
}
#endregion Public Methods
#region Internal Methods
/// <summary>
/// Draws not tiled image
/// </summary>
/// <param name="e"></param>
/// <param name="drawRect"></param>
internal virtual void DrawImageInternal(FRPaintEventArgs e, RectangleF drawRect)
{
bool rotate = Angle == 90 || Angle == 270;
float imageWidth = ImageWidth;//rotate ? Image.Height : Image.Width;
float imageHeight = ImageHeight;//rotate ? Image.Width : Image.Height;
PointF upperLeft;
PointF upperRight;
PointF lowerLeft;
System.Drawing.Drawing2D.Matrix matrix = e.Graphics.Transform;
GetImageAngleTransform(drawRect, imageWidth, imageHeight, e.ScaleX, e.ScaleY, matrix.OffsetX, matrix.OffsetY, out upperLeft, out upperRight, out lowerLeft);
DrawImageInternal2(e.Graphics, upperLeft, upperRight, lowerLeft);
}
#endregion Internal Methods
#region Protected Methods
protected abstract void DrawImageInternal2(IGraphics graphics, PointF upperLeft, PointF upperRight, PointF lowerLeft);
/// <summary>
/// Reset index of image
/// </summary>
protected abstract void ResetImageIndex();
/// <summary>
/// When auto size was updated, internal use only
/// </summary>
protected void UpdateAutoSize()
{
if (SizeMode == PictureBoxSizeMode.AutoSize)
{
if (ImageWidth == 0 || ImageHeight == 0)
{
if (IsRunning && !IsPrinting)
{
Width = 0;
Height = 0;
}
}
else
{
//bool rotate = Angle == 90 || Angle == 270;
//Width = (rotate ? Image.Height : Image.Width) + Padding.Horizontal;
//Height = (rotate ? Image.Width : Image.Height) + Padding.Vertical;
PointF[] p = new PointF[4];
p[0] = new PointF(-ImageWidth / 2, -ImageHeight / 2);
p[1] = new PointF(ImageWidth / 2, -ImageHeight / 2);
p[2] = new PointF(ImageWidth / 2, ImageHeight / 2);
p[3] = new PointF(-ImageWidth / 2, ImageHeight / 2);
float minX = float.MaxValue;
float maxX = float.MinValue;
float minY = float.MaxValue;
float maxY = float.MinValue;
for (int i = 0; i < 4; i++)
{
p[i] = rotateVector(p[i], Angle);
if (minX > p[i].X) minX = p[i].X;
if (maxX < p[i].X) maxX = p[i].X;
if (minY > p[i].Y) minY = p[i].Y;
if (maxY < p[i].Y) maxY = p[i].Y;
}
Width = maxX - minX;
Height = maxY - minY;
// if width/height restrictions are set, use zoom mode to keep aspect ratio
if (IsRunning && (MaxWidth != 0 || MaxHeight != 0))
SizeMode = PictureBoxSizeMode.Zoom;
}
}
}
#endregion Protected Methods
/// <inheritdoc/>
public override string[] GetExpressions()
{
List<string> expressions = new List<string>();
expressions.AddRange(base.GetExpressions());
if (!String.IsNullOrEmpty(DataColumn))
expressions.Add(DataColumn);
if (!String.IsNullOrEmpty(ImageSourceExpression))
{
if (ImageSourceExpression.StartsWith("[") && ImageSourceExpression.EndsWith("]"))
{
expressions.Add(ImageSourceExpression.Substring(1, ImageSourceExpression.Length - 2));
}
else
{
expressions.Add(ImageSourceExpression);
}
}
return expressions.ToArray();
}
internal void SetImageLocation(string value, bool forceUpdate)
{
if (!String.IsNullOrEmpty(Config.ReportSettings.ImageLocationRoot))
imageLocation = value.Replace(Config.ReportSettings.ImageLocationRoot, "");
else
imageLocation = value;
if (forceUpdate)
UpdateImageLocation();
}
internal void UpdateImageLocation()
{
LoadImage();
ResetImageIndex();
}
}
}
Loading...
Report
Report success
We will send you the feedback within 2 working days through the letter!
Please fill in the reason for the report carefully. Provide as detailed a description as possible.
Please select a report type
Cancel
Send
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

Releases

No release

Contributors

All

Language(Optional)

Activities

can not load any more
Edit
About
Homepage
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/star8521/FastReport.git
git@gitee.com:star8521/FastReport.git
star8521
FastReport
FastReport
master
Going to Help Center

Search

Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register

AltStyle によって変換されたページ (->オリジナル) /