GR32.ImageFormats.TMetaFile.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. unit GR32.ImageFormats.TMetaFile;
  2. (* ***** BEGIN LICENSE BLOCK *****
  3. * Version: MPL 1.1 or LGPL 2.1 with linking exception
  4. *
  5. * The contents of this file are subject to the Mozilla Public License Version
  6. * 1.1 (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. * http://www.mozilla.org/MPL/
  9. *
  10. * Software distributed under the License is distributed on an "AS IS" basis,
  11. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. * for the specific language governing rights and limitations under the
  13. * License.
  14. *
  15. * Alternatively, the contents of this file may be used under the terms of the
  16. * Free Pascal modified version of the GNU Lesser General Public License
  17. * Version 2.1 (the "FPC modified LGPL License"), in which case the provisions
  18. * of this license are applicable instead of those above.
  19. * Please see the file LICENSE.txt for additional information concerning this
  20. * license.
  21. *
  22. * The Original Code is image format support for Graphics32
  23. *
  24. * The Initial Developer of the Original Code is
  25. * Anders Melander <[email protected]>
  26. *
  27. * Portions created by the Initial Developer are Copyright (C) 2008-2022
  28. * the Initial Developer. All Rights Reserved.
  29. *
  30. * Contributor(s):
  31. *
  32. * ***** END LICENSE BLOCK ***** *)
  33. interface
  34. {$include GR32.inc}
  35. implementation
  36. uses
  37. Classes,
  38. Graphics,
  39. SysUtils,
  40. {$ifndef FPC}
  41. Consts,
  42. {$endif FPC}
  43. GR32,
  44. GR32.ImageFormats.TGraphic,
  45. GR32.ImageFormats;
  46. //------------------------------------------------------------------------------
  47. //
  48. // TImageFormatAdapterTMetaFile
  49. //
  50. //------------------------------------------------------------------------------
  51. // Implements IImageFormatAdapter for the TMetaFile class.
  52. //------------------------------------------------------------------------------
  53. type
  54. TImageFormatAdapterTMetaFile = class(TImageFormatReaderTGraphic,
  55. IImageFormatAdapter)
  56. strict protected
  57. // IImageFormatAdapter
  58. function CanAssignFrom(Source: TPersistent): boolean; override;
  59. function AssignFrom(Dest: TCustomBitmap32; Source: TPersistent): boolean; override;
  60. function CanAssignTo(Dest: TPersistent): boolean; override;
  61. function AssignTo(Source: TCustomBitmap32; Dest: TPersistent): boolean; override;
  62. end;
  63. //------------------------------------------------------------------------------
  64. // IImageFormatAdapter
  65. //------------------------------------------------------------------------------
  66. function TImageFormatAdapterTMetaFile.CanAssignTo(Dest: TPersistent): boolean;
  67. begin
  68. Result := False;
  69. end;
  70. function TImageFormatAdapterTMetaFile.AssignTo(Source: TCustomBitmap32; Dest: TPersistent): boolean;
  71. begin
  72. Result := False;
  73. end;
  74. function TImageFormatAdapterTMetaFile.CanAssignFrom(Source: TPersistent): boolean;
  75. begin
  76. {$IFDEF PLATFORM_INDEPENDENT}
  77. Result := False;
  78. {$ELSE}
  79. Result := inherited;
  80. {$ENDIF}
  81. end;
  82. function TImageFormatAdapterTMetaFile.AssignFrom(Dest: TCustomBitmap32; Source: TPersistent): boolean;
  83. begin
  84. {$IFDEF PLATFORM_INDEPENDENT}
  85. Result := False;
  86. {$ELSE}
  87. if (not (Source is TMetaFile)) then
  88. Exit(False);
  89. Result := True;
  90. AssignFromGraphicMasked(Dest, TGraphic(Source))
  91. {$ENDIF}
  92. end;
  93. //------------------------------------------------------------------------------
  94. //------------------------------------------------------------------------------
  95. //------------------------------------------------------------------------------
  96. var
  97. ImageFormatHandle: integer = 0;
  98. initialization
  99. {$IFNDEF PLATFORM_INDEPENDENT}
  100. ImageFormatHandle := ImageFormatManager.RegisterImageFormat(
  101. TImageFormatAdapterTMetaFile.Create(TMetaFile, SVMetafiles, ['wmf', 'emf']),
  102. ImageFormatPriorityNormal);
  103. {$ENDIF}
  104. finalization
  105. ImageFormatManager.UnregisterImageFormat(ImageFormatHandle);
  106. end.