⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flexutils.int

📁 FlexGraphics是一套创建矢量图形的VCL组件
💻 INT
📖 第 1 页 / 共 2 页
字号:
/////////////////////////////////////////////////////////
//                                                     //
//    FlexGraphics library                             //
//    Copyright (c) 2002-2009 FlexGraphics software.  //
//                                                     //
//    Utility procedures and functions                 //
//                                                     //
/////////////////////////////////////////////////////////

unit FlexUtils;

{$I FlexDefs.inc}

interface

uses
  Windows, Forms, Dialogs, Controls, Messages, Classes, 
  {$IFDEF FG_D6} Variants, RTLConsts, {$ENDIF} SysUtils,
  TypInfo, Graphics, ClipBrd, Consts;

const
  // FlexGraphics document clipboard format
  CF_FLEXDOC : Word = 0;

  // Reserved word's in fxd format
  fcDocument  = 'document';
  fcClipboard = 'clipboard';
  fcLibrary   = 'library';
  fcObject    = 'object';
  fcProperty  = 'property';
  fcEnd       = 'end';
  fcBinary    = 'flexbinary';

  // array of all reserved words
  fcReserved: array[0..6] of string = (
    fcDocument, fcClipboard, fcLibrary, fcObject, fcProperty, fcEnd, fcBinary );

  IndentStep  = '  ';

  BooleanWords: array[boolean] of string = ( 'False', 'True' );

  // Flex binary commands
  fbcUnknown           = $0000; // Not a commmand (unknown command)

  fbcDocument          = $0001; // Key0: Document name, No data
  fbcClipboard         = $0002; // No keys, No data
  fbcLibrary           = $0003; // Key0: Library name, No data
  fbcObject            = $0004; // Key0: Object name, Key1: Class name, No data
  fbcProperty          = $0005; // Key0: Property name, [Key1: property value],
                                // DataBlock: TFlexBinPropertyData
  fbcComplexProperty   = $0006; // Key0: Property name, No data
  fbcEnd               = $0007; // No keys, No data
  fbcReduceDictionary  = $0008; // No keys,
                                // DataBlock: TFlexBinReduceDictionaryData
  fbcBinaryEnd         = $0009; // No keys, No data

  fbcUser              = $1000; // 0..65535 keys, [DataBlock: User type]

  // Flex binary key flags
  fbkIndexSizeMask     = $03; // 2 bits
   fbkIndexByte        = $01; // Next number is byte
   fbkIndexWord        = $02; // Next number is word
   fbkIndexDWord       = $03; // Next number is double word
  fbkIsIndex           = $04; // 1 bit - Next number is index in keys dictinary
                              //         Else is length of the following
                              //         key string
  fbkDontStore         = $08; // 1 bit - This new key must not be stored in
                              //         keys dictionary

  // FlexBinary supported properties types
  fbpEmpty             = $0000; { vt_empty        0 }
  fbpNull              = $0001; { vt_null         1 }
  fbpSmallint          = $0002; { vt_i2           2 }
  fbpInteger           = $0003; { vt_i4           3 }
  fbpSingle            = $0004; { vt_r4           4 }
  fbpDouble            = $0005; { vt_r8           5 }
  fbpCurrency          = $0006; { vt_cy           6 }
  fbpDate              = $0007; { vt_date         7 }
  // fbpOleStr         = $0008; { vt_bstr         8 }
  // fbpDispatch       = $0009; { vt_dispatch     9 }
  // fbpError          = $000A; { vt_error       10 }
  fbpBoolean           = $000B; { vt_bool        11 }
  // fbpVariant        = $000C; { vt_variant     12 }
  // fbpUnknown        = $000D; { vt_unknown     13 }
  fbpShortInt          = $0010; { vt_i1          16 }
  fbpByte              = $0011; { vt_ui1         17 }
  fbpWord              = $0012; { vt_ui2         18 }
  fbpLongWord          = $0013; { vt_ui4         19 }
  fbpInt64             = $0014; { vt_i8          20 }
  fbpString            = $0100; { Pascal string 256 } {not OLE compatible }

  fbpStrList           = $0200; { FlexGraphics string list }
  fbpHexData           = $0201; { FlexGraphics hex data block }

  // Cursors in InDesign mode
  crShapeCursor           = 1;
  crShapeAddCursor        = 2;
  crShapeDelCursor        = 3;
  crShapeCloseCursor      = 4;
  crShapeMoveCursor       = 5;
  crShapeMoveCurveCursor  = 6;

  crCreateControlCursor   = 7;
  crCreateRectCursor      = 8;
  crCreateEllipseCursor   = 9;
  crCreateTextCursor      = 10;
  crCreatePicCursor       = 11;
  crCreatePolyCursor      = 12;

  crZoomInCursor          = 13;
  crZoomOutCursor         = 14;

  crPanCursor             = 15;
  crPanningCursor         = 16;

  crShapeContinueCursor   = 17;
  crShapeMoveLineCursor   = 18;

  crLastFlexCursor        = 49;

  // Scaling
  FloatDisplayFormat: string = '%.3f';
  PixelScaleFactor = 1000;

type
  TFlexNotify = (
    fnName, fnID, fnRect, fnAnchorPoints, fnEditPoints, fnLinkPoints,
    fnOrder,  fnParent, fnLoaded,
    fnLayers, fnSchemes, fnCreated, fnDestroyed, fnSelect, fnSelectPoint,
    fnScale, fnPan, fnChange{User generic} );

  PTranslateInfo = ^TTranslateInfo;
  TTranslateInfo = record
   Center: TPoint;  // in document (owner) coordinate system
   Rotate: integer; // counterclockwise degree
   Mirror: boolean; // horizontal mirroring
  end;

  TBitmapDisplay = ( bdCenter, bdTile, bdStretch );

  PTiledBitmapCache = ^TTiledBitmapCache;
  TTiledBitmapCache = record
   Handle: HBitmap;
   Width: integer;
   Height: integer;
  end;

  TBooleanArray = array of boolean;

  TGradientStyle = (
    gsHorizontal, gsVertical, gsSquare, gsElliptic,
    gsTopLeft, gsTopRight, gsBottomLeft, gsBottomRight );

  TFlexFiler = class;

  TFlexFilerProcess = ( ppUnknown, ppLoad, ppSave, ppCopy );

  // Flex binary command
  // <Header> [<Keys>] [<Data>]
  // <Header>: <TFlexBinHeader>
  // <Keys>: { <Key>, ... }
  // <Key>:  <KeyOptions>: byte, <KeyIndexOrLen>: Byte..DWord, [ <Key chars> ]
  //         KeyIndexOrLen = 0 - Empty string
  //         KeyIndexOrLen > 0 - Index of key in dictionary OR
  //                             Length of new key to load
  //                             (depend from <KeyOptions> flags)              
  // <Data>: <TFlexBinPropertyData> | <User defined type>

  PFlexBinHeader = ^TFlexBinHeader;
  TFlexBinHeader = packed record
   Command: word;
   KeyCount: word;
   Size: integer;
  end;

  PFlexBinPropertyData = ^TFlexBinPropertyData;
  TFlexBinPropertyData = packed record
   case PropType: cardinal of
    fbpEmpty,
    fbpNull:           ( );
    fbpSmallint:       ( VSmallInt: SmallInt );
    fbpInteger:        ( VInteger: integer );
    fbpSingle:         ( VSingle: single );
    fbpDouble:         ( VDouble: double );
    fbpCurrency:       ( VCurrency: currency );
    fbpDate:           ( VDate: {$IFDEF FG_CBUILDER} double
                                {$ELSE}              TDateTime {$ENDIF} );
    fbpBoolean:        ( VBoolean: integer {!} );
    fbpShortInt:       ( VShortInt: ShortInt );
    fbpByte:           ( VByte: Byte );
    fbpWord:           ( VWord: Word );
    fbpLongWord:       ( VLongWord: LongWord );
    fbpInt64:          ( VInt64: Int64 );
    fbpString:         ( VString: integer {KeyIndex arg number} );
    fbpStrList:        ( VStrings: record
                          StrCount: integer;
                          StrData: record end; {<Len: Int>[<Chars>], ...}
                         end );
    fbpHexData:        ( VHexData: record end );  // <Binary block data>
  end;

  PFlexBinReduceDicData = ^TFlexBinReduceDicData;
  TFlexBinReduceDicData = packed record
   DeleteCount: integer;
  end;

  TFlexBinKeyStore = (
    fbsObjectName, fbsClassName, fbsPropertyName, fbsPropertyValue );
  TFlexBinKeyStoreSet = set of TFlexBinKeyStore;

  TFlexBinaryData = class
  protected
   FOwner: TFlexFiler;
   FProcess: TFlexFilerProcess;
   FFinished: boolean;
   // Keys dictionary
   FDictionary: TStringList;
   FDicCapacity: integer;
   FDicDeleteCount: integer;
   // Key types don't store options
   FKeyDontStore: TFlexBinKeyStoreSet;
   // Keys for Read/Write commands
   FCmdKeys: TStringList;
   FCmdKeyCount: integer;
   FCmdKeysSize: integer;
   // Last ReadCommand() data
   FCmdReadHeader: TFlexBinHeader;
   FCmdReadDataSize: integer;
   FCmdReadUserData: pointer;
   FCmdReadUserDataSize: integer;
   FCmdReadDataAhead: boolean;
   // Helpers for LoadStrCheck()
   FReadPropLines: TStringList;
   FReadPropLine: integer;
   // Helpers for SaveStr()
   FWritePropType: integer;
   FWritePropName: string;
   FWritePropData: pointer;
   FWritePropDataPos: integer;
   FWritePropDataSize: integer;
   procedure SetProcess(const Value: TFlexFilerProcess);
   procedure SetDicCapacity(const Value: integer);
   procedure SetDicDeleteCount(const Value: integer);
   function  GetReadKey(Index: integer): string;
   function  GetPropertyDataSize(PropType: integer;
     const Value: Variant): integer;
   function  AddKey(const Key: string; var KeyIndex: integer): boolean;
   function  AddWriteKey(const Key: string; DontStore: boolean = false): integer;
   function  ReadKey: boolean;
   procedure WriteKey(const Key: string; KeyIndex: integer;
     DontStore: boolean = false);
   procedure ResetWriteKeys;
   function  ReadCommandHeaderAndKeys(var Header: TFlexBinHeader): boolean;
   function  WriteCommandHeaderAndKeys(Command: word;
     DataSize: integer): boolean;
   function  ReadPropertyData(var Value: Variant;
     var PropType: integer): boolean;
   function  AllocReadData: pointer;
   procedure ClearReadData;
   function  GrowWriteData(Size: integer): pointer;
   procedure ClearWriteData;
   procedure CheckDontStore(Command: word;
     var DontStoreKey1, DontStoreKey2: boolean);
   procedure ReduceDictionary(ACount: integer);
  public
   constructor Create(AOwner: TFlexFiler);
   destructor Destroy; override;
   procedure Reset;
   function  LoadStrCheck(out s: string): boolean;
   procedure SaveStr(const s: string);
   procedure SaveStrBuf(Buf: pointer; BufSize: integer);
   function  ReadCommand: boolean;
   function  ReadCommandData(out Value: Variant): integer;
   function  ReadCommandUserData: pointer;
   function  WritePropertyCommand(const PropName: string; PropType: integer;
     const Value: Variant; DontStoreValueKey: boolean = false): boolean;
   procedure WriteSimpleCommand(Command: word; KeyCount: integer = 0;
     const Key1: string = ''; const Key2: string = '';
     DontStoreKey1: boolean = false; DontStoreKey2: boolean = false);
   procedure WriteDataCommand(Command: word; var Data; DataSize: integer;
     KeyCount: integer = 0; const Key1: string = ''; const Key2: string = '';
     DontStoreKey1: boolean = false; DontStoreKey2: boolean = false);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -