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

📄 gmobjects.pas

📁 GmPrintSuite 2.96.7] a
💻 PAS
📖 第 1 页 / 共 4 页
字号:
  AClipRect: TRect;
  PClipRect: PRect;
begin
  inherited DrawToCanvas(ACanvas, Data);
  TokenizedText := Tokenize(FCaption, Data.Page, Data.NumPages,
    GlobalDateTokenFormat, GlobalTimeTokenFormat);

  xy.X := Round(X[gmInches] * Data.PpiX);
  xy.y := Round(Y[gmInches] * Data.PpiY);
  if not EqualGmRects(FClipRect, GmRect(-1, -1, -1, -1)) then
  begin
    AClipRect.Left   := Round(FClipRect.Left * Data.PpiX);
    AClipRect.Right  := Round(FClipRect.Right * Data.PpiX);
    AClipRect.Top    := Round(FClipRect.Top * Data.PpiY);
    AClipRect.Bottom := Round(FClipRect.Bottom * Data.PpiY);
    PClipRect := @AClipRect;
  end
  else
    PClipRect := nil;

  ExtTextOut(ACanvas.Handle, xy.X, xy.Y, ETO_CLIPPED, PClipRect, PChar(TokenizedText), Length(TokenizedText), nil)

  {if FFont.Angle <> 0 then
    ExtTextOut(ACanvas.Handle, xy.X, xy.Y, ETO_CLIPPED, PClipRect, PChar(TokenizedText), Length(TokenizedText), nil)
  else
    GmFontMapper.TextOut(ACanvas, xy.X, xy.Y, PClipRect, TokenizedText);}
end;

procedure TGmTextObject.OffsetObject(x, y: Extended; Measurement: TGmMeasurement);
begin
  Self.X[gmInches] := Self.X[gmInches] + ConvertValue(x, Measurement, gmInches);
  Self.Y[gmInches] := Self.Y[gmInches] + ConvertValue(y, Measurement, gmInches);
end;

//------------------------------------------------------------------------------

// *** TGmLineObject ***

function TGmLineObject.GetObjectID: integer;
begin
  Result := GM_LINE_OBJECT_ID;
end;

procedure TGmLineObject.DrawToCanvas(ACanvas: TCanvas; var Data: TGmObjectDrawData);
begin
  inherited DrawToCanvas(ACanvas, Data);
  ACanvas.MoveTo(Round(X[gmInches] * Data.PpiX), Round(Y[gmInches] * Data.PpiY));
  ACanvas.LineTo(Round(X2[gmInches] * Data.PpiX), Round(Y2[gmInches] * Data.PpiY));
end;

function TGmLineObject.BoundingRect(Data: TGmObjectDrawData): TGmRectPoints;
var
  ARect: TRect;
begin
  ARect := CoordsAsPixels(Data.PpiX, Data.PpiY);
  InflateRect(ARect, 3, 3);
  Result := RectToGmRectPoints(ARect);
end;
//------------------------------------------------------------------------------

// *** TGmGraphicObject ***

constructor TGmGraphicObject.Create(AResourceTable: TGmResourceTable);
begin
  inherited Create(AResourceTable);
  FCopyMode := cmSrcCopy;
  FPrintPixelFormat := pf8bit;
end;

function TGmGraphicObject.GetObjectID: integer;
begin
  Result := GM_GRAPHIC_OBJECT_ID;
end;

procedure TGmGraphicObject.LoadFromValueList(Values: TGmValueList);
begin
  inherited LoadFromValueList(Values);
  FCopyMode         := TCopyMode(Values.ReadIntValue(C_CM, Ord(cmSrcCopy)));
  FPrintPixelFormat := TPixelFormat(Values.ReadIntValue(C_PF, Ord(pf8bit)));
  FGraphic          := ResourceTable.GraphicList.Graphic[Values.ReadIntValue(C_G, -1)];
end;

procedure TGmGraphicObject.SaveToValueList(Values: TGmValueList);
begin
  inherited SaveToValueList(Values);
  Values.WriteIntValue(C_CM, Ord(FCopyMode));
  Values.WriteIntValue(C_PF, Ord(FPrintPixelFormat));
  if Assigned(FGraphic) then
    Values.WriteIntValue(C_G, ResourceTable.GraphicList.IndexOf(FGraphic));
end;

procedure TGmGraphicObject.SetGraphic(AGraphic: TGraphic);

  function SupportedGraphic(AGraphic: TGraphic): Boolean;
  begin
    Result := (AGraphic is TBitmap) or
              (AGraphic is TMetafile) or
              (AGraphic is TJPEGImage);
  end;

var
  ABitmap: TBitmap;
  AJpeg: TJPEGImage;
begin
  if (AGraphic is TIcon) then
  begin
    IconToBitmap((AGraphic as TIcon), ABitmap);
    FGraphic := ResourceTable.GraphicList.AddGraphic(ABitmap);
    ABitmap.Free;
  end
  else
  if SupportedGraphic(AGraphic) then
  begin
    FGraphic := ResourceTable.GraphicList.AddGraphic(AGraphic)
  end
  else
  begin
    GraphicToJPeg(AGraphic, AJpeg);
    FGraphic := ResourceTable.GraphicList.AddGraphic(AJpeg);
    AJpeg.Free;
  end;
  if (FGraphic is TBitmap) then
    FPrintPixelFormat := (FGraphic as TBitmap).PixelFormat;
end;

procedure TGmGraphicObject.DrawToCanvas(ACanvas: TCanvas; var Data: TGmObjectDrawData);
var
  ABitmap: TBitmap;
begin
  if FGraphic = nil then Exit;
  ACanvas.CopyMode := FCopyMode;
  if (Graphic is TBitmap) or (Graphic is TJpegImage) then
  begin
    ABitmap := TBitmap.Create;
    try
      ABitmap.Assign(Graphic);
      if IsPrinterCanvas(ACanvas) then
      begin
        ABitmap.PixelFormat := FPrintPixelFormat;
        PrintBitmap(ACanvas, CoordsAsPixels(Data.PpiX, Data.PpiY), ABitmap);
      end
      else
        ACanvas.StretchDraw(CoordsAsPixels(Data.PpiX, Data.PpiY), ABitmap);
    finally
      ABitmap.Free;
    end;
  end
  else
    ACanvas.StretchDraw(CoordsAsPixels(Data.PpiX, Data.PpiY), Graphic);
end;

//------------------------------------------------------------------------------

// *** TGmTextBoxObject ***

constructor TGmTextBoxObject.Create(AResourceTable: TGmResourceTable);
begin
  inherited Create(AResourceTable);
  FAlignment := taLeftJustify;
  FClipText := True;
  FVertAlignment := gmTop;
  FWordBreak := True;
end;

procedure TGmTextBoxObject.SetAlignment(Value: TAlignment);
begin
  if FAlignment = Value then Exit;
  FAlignment := Value;
  Changed;
end;

procedure TGmTextBoxObject.SetClipText(Value: Boolean);
begin
  if FClipText = Value then  Exit;
  FClipText := Value;
  Changed;
end;

procedure TGmTextBoxObject.SetPadding(Value: Extended);
begin
  if FPadding = Value then Exit;
  FPadding := Value;
  Changed;
end;

procedure TGmTextBoxObject.SetWordBreak(Value: Boolean);
begin
  if FWordBreak = Value then Exit;
  FWordBreak := Value;
  Changed;
end;

procedure TGmTextBoxObject.SetVertAlignment(Value: TGmVertAlignment);
begin
  if FVertAlignment = Value then Exit;
  FVertAlignment := Value;
  Changed;
end;

function TGmTextBoxObject.GetObjectID: integer;
begin
  Result := GM_TEXTBOX_OBJECT_ID;
end;

procedure TGmTextBoxObject.LoadFromValueList(Values: TGmValueList);
begin
  inherited LoadFromValueList(Values);
  FCoords.BottomRight := Values.ReadGmPointValue(C_XY2, GmPoint(0,0));
  FPadding            := Values.ReadExtValue(C_TP, 0);
  FTextHeight         := Values.ReadExtValue(C_TH, 0);
  FCaption            := Values.ReadStringValue(C_T, '');
  FAlignment          := TAlignment(Values.ReadIntValue(C_TA, Ord(taLeftJustify)));
  FVertAlignment      := TGmVertAlignment(Values.ReadIntValue(C_VA, Ord(gmTop)));
  FClipText           := Values.ReadBoolValue(C_CT, True);
  FWordBreak          := Values.ReadBoolValue(C_WB, True);
  FFont               := ResourceTable.FontList.Font[Values.ReadIntValue(C_F, -1)];
end;

procedure TGmTextBoxObject.SaveToValueList(Values: TGmValueList);
begin
  inherited SaveToValueList(Values);
  Values.WriteGmPointValue(C_XY2, FCoords.BottomRight);
  Values.WriteExtValue(C_TP, FPadding);
  Values.WriteExtValue(C_TH, FTextHeight);
  Values.WriteStringValue(C_T, FCaption);
  if FAlignment <> taLeftJustify then Values.WriteIntValue(C_TA, Ord(FAlignment));
  if FVertAlignment <> gmTop then Values.WriteIntValue(C_VA, Ord(FVertAlignment));
  if FClipText <> True then Values.WriteBoolValue(C_CT, FClipText);
  if FWordBreak <> True then Values.WriteBoolValue(C_WB, FWordBreak);
  Values.WriteIntValue(C_F, ResourceTable.FontList.IndexOf(FFont));
end;

procedure TGmTextBoxObject.DrawToCanvas(ACanvas: TCanvas; var Data: TGmObjectDrawData);
var
  AsPixels: TRect;
  PaddingPixels: TPoint;
  TextHeightPixels: Integer;
  TextRect: TRect;
  PaddedRect: TRect;
  TokenizedText: string;
  AAlignment: Byte;
begin
  inherited DrawToCanvas(ACanvas, Data);
  TokenizedText := Tokenize(FCaption, Data.Page, Data.NumPages,
    GlobalDateTokenFormat, GlobalTimeTokenFormat);
  AsPixels := CoordsAsPixels(Data.PpiX, Data.PpiY);
  TextHeightPixels := Round(FTextHeight * Data.PpiY);
  TextRect := AsPixels;
  PaddedRect := TextRect;
  case FVertAlignment of
    gmMiddle: PaddedRect.Top := PaddedRect.Top + ((RectHeight(PaddedRect)- TextHeightPixels) div 2);
    gmBottom: PaddedRect.Top := (PaddedRect.Bottom - TextHeightPixels);
  end;
  PaddingPixels.X := Round(FPadding * Data.PpiX);
  PaddingPixels.Y := Round(FPadding * Data.PpiY);
  InflateRect(PaddedRect, 0-PaddingPixels.X, 0-PaddingPixels.Y);
  GmDrawRect(ACanvas, AsPixels);

  AAlignment := DT_LEFT;
  case FAlignment of
    taCenter: AAlignment := DT_CENTER;
    taRightJustify: AAlignment := DT_RIGHT;
  end;

  if not FWordBreak then
    DrawTextEx(ACanvas.Handle, PChar(TokenizedText), Length(TokenizedText), PaddedRect, DT_EXPANDTABS or AAlignment, nil)
  else
    DrawTextEx(ACanvas.Handle, PChar(TokenizedText), Length(TokenizedText), PaddedRect, DT_WORDBREAK or DT_EXPANDTABS	or AAlignment, nil)


  //GmFontMapper.WrapText := FWordBreak;
  //GmFontMapper.TextBox(ACanvas, PaddedRect, TokenizedText, FAlignment, Data.FastDraw);
end;

//------------------------------------------------------------------------------

// *** TGmRectangleShape ***

function TGmRectangleShape.GetObjectID: integer;
begin
  Result := GM_RECTANGLE_OBJECT_ID;
end;

procedure TGmRectangleShape.DrawToCanvas(ACanvas: TCanvas; var Data: TGmObjectDrawData);
begin
  inherited DrawToCanvas(ACanvas, Data);
  GmDrawRect(ACanvas, CoordsAsPixels(Data.PpiX, Data.PpiY));
end;

//------------------------------------------------------------------------------

// *** TGmEllipseShape ***

function TGmEllipseShape.GetObjectID: integer;
begin
  Result := GM_ELLIPSE_OBJECT_ID;
end;

procedure TGmEllipseShape.DrawToCanvas(ACanvas: TCanvas; var Data: TGmObjectDrawData);
var
  R: TRect;
begin
  inherited DrawToCanvas(ACanvas, Data);
  R := CoordsAsPixels(Data.PpiX, Data.PpiY);
  BeginPath(ACanvas.Handle);
  GmDrawEllipse(ACanvas, R.Left, R.Top, R.Right, R.Bottom);
  EndPath(ACanvas.Handle);
  StrokeAndFillPath(ACanvas.Handle);
end;

//------------------------------------------------------------------------------

// *** TGmSemiComplexShape ***

function TGmSemiComplexShape.GetX3(Measurement: TGmMeasurement): Extended;
begin
  Result := ConvertValue(FX3, gmInches, Measurement)
end;

function TGmSemiComplexShape.GetY3(Measurement: TGmMeasurement): Extended;
begin
  Result := ConvertValue(FY3, gmInches, Measurement)
end;

procedure TGmSemiComplexShape.SetX3(Measurement: TGmMeasurement; const Value: Extended);
var
  NewValue: Extended;
begin
  NewValue := ConvertValue(Value, Measurement, gmInches);
  if FX3 = NewValue then Exit;
  FX3 := NewValue;
  Changed;
end;

procedure TGmSemiComplexShape.SetY3(Measurement: TGmMeasurement; const Value: Extended);
var
  NewValue: Extended;
begin
  NewValue := ConvertValue(Value, Measurement, gmInches);
  if FY3 = NewValue then Exit;
  FY3 := NewValue;
  Changed;
end;

procedure TGmSemiComplexShape.LoadFromValueList(Values: TGmValueList);
var
  XY3: TGmPoint;
begin
  inherited LoadFromValueList(Values);
  XY3 := Values.ReadGmPointValue(C_XY3, GmPoint(0,0));
  FX3 := XY3.X;
  FY3 := XY3.Y;
end;

procedure TGmSemiComplexShape.SaveToValueList(Values: TGmValueList);
var
  XY3: TGmPoint;
begin
  inherited SaveToValueList(Values);
  XY3 := GmPoint(FX3, FY3);
  Values.WriteGmPointValue(C_XY3, XY3);
end;

procedure TGmSemiComplexShape.OffsetObject(x, y: Extended; Measurement: TGmMeasurement);
var
  InchOffsetX: Extended;
  InchOffsetY: Extended;
begin
  InchOffsetX := ConvertValue(x, Measurement, gmInches);
  InchOffsetY := ConvertValue(y, Measurement, gmInches);
  FX3 := FX3 + InchOffsetX;
  FY3 := FY3 + InchOffsetY;
  inherited OffsetObject(x, y, Measurement);
end;

//------------------------------------------------------------------------------

// *** TGmRoundRectShape ***

function TGmRoundRectShape.GetObjectID: integer;
begin
  Result := GM_ROUNDRECT_OBJECT_ID;
end;

procedure TGmRoundRectShape.DrawToCanvas(ACanvas: TCanvas; var Data: TGmObjectDrawData);
var
  R: TRect;
  C: TPoint;
begin
  inherited DrawToCanvas(ACanvas, Data);
  R := CoordsAsPixels(Data.PpiX, Data.PpiY);
  C.X := Round(X3[gmInches] * Data.PpiX);
  C.Y := Round(Y3[gmInches] * Data.PpiY);
  BeginPath(ACanvas.Handle);
  GmDrawRoundRect(ACanvas, R.Left, R.Top, R.Right, R.Bottom, C.X, C.Y);
  EndPath(ACanvas.Handle);
  StrokeAndFillPath(ACanvas.Handle);
end;

//------------------------------------------------------------------------------

// *** TGmComplexShape ***

function TGmComplexShape.GetCoords(index: TGmMeasurement): TGmComplexCoords;
begin
  Result.X  := X[index];
  Result.Y  := Y[index];
  Result.X2 := X2[index];
  Result.Y2 := Y2[index];
  Result.X3 := X3[index];
  Result.Y3 := Y3[index];
  Result.X4 := X4[index];
  Result.Y4 := Y4[index];
end;

function TGmComplexShape.GetX4(index: TGmMeasurement): Extended;
begin
  Result := ConvertValue(FX4, gmInches, index);
end;

function TGmComplexShape.GetY4(index: TGmMeasurement): Extended;
begin
  Result := ConvertValue(FY4, gmInches, index);
end;

procedure TGmComplexShape.SetCoords(index: TGmMeasurement; Value: TGmComplexCoords);

⌨️ 快捷键说明

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