QRDBRichRext will export as an image. Replace the procedure below in QRCtrls.pasRichText Export Procedure ========================= This is the replacement for the current procedure. Code has been added to export an image of the RTF control. This code is in QRCtrls.pas. procedure TQRCustomRichText.Print(OfsX, OfsY : integer); var Range: TFormatRange; LogX, LogY : integer; TextLength : integer; HasExpanded : boolean; OldMapMode : integer; ARichEdit : TCustomRichEdit; Expanded : extended; RTFImage : TQRImage; expht, expwid : integer; RTFMeta : TMetafile; metacanvas : TMetafilecanvas; function Render(RenderIt : boolean) : integer; begin if RenderIt then Result := SendMessage(ARichEdit.Handle, EM_FORMATRANGE, 0, Longint(@Range)) else Result := SendMessage(ARichEdit.Handle, EM_FORMATRANGE, 1, Longint(@Range)); end; begin if assigned(FParentRichEdit) then ARichEdit := ParentRichEdit else ARichEdit := FRichEdit; FillChar(Range, SizeOf(TFormatRange), 0); with Range do begin hdc := ParentReport.QRPrinter.Canvas.Handle; hdcTarget := hdc; LogX := GetDeviceCaps(hdc, LOGPIXELSX); LogY := GetDeviceCaps(hdc, LOGPIXELSY); rc := Rect(QRPrinter.XPos(OfsX + Size.Left) * 1440 div LogX, QRPrinter.YPos(OfsY + Size.Top) * 1440 div LogY, QRPrinter.XPos(OfsX + Size.Left + Size.Width) * 1440 div LogX, QRPrinter.YPos(OfsY + Size.Top + Size.Height) * 1440 div LogY); rcPage := Rect(0, 0, QRPrinter.XSize(QRPrinter.PaperWidth) * 1440 div LogX, QRPrinter.YSize(QRPrinter.PaperLength) * 1440 div LogY); if PrintFinished then LastChar := 0; HasExpanded := false; Expanded := 0; TextLength := ARichEdit.GetTextLen; chrg.cpMax := -1; chrg.cpMin := LastChar; OldMapMode := SetMapMode(hdc, MM_TEXT); LastChar := Render(false); if (LastChar < TextLength) and AutoStretch and (Parent is TQRCustomBand) and (TextLength > 0) then begin PrintFinished := false; while (LastChar <= TextLength) and TQRCustomBand(Parent).CanExpand(50) do begin TQRCustomBand(Parent).ExpandBand(50, Expanded, HasExpanded); rc.Bottom := QRPrinter.YPos(OfsY + Size.Top + Size.Height + Expanded) * 1440 div LogY; LastChar := Render(false); end; LastChar := Render(true); if (LastChar >= TextLength) or (LastChar = -1) then begin LastChar := TextLength; PrintFinished := true; end end else begin LastChar := Render(true); PrintFinished := true; inherited; end; end; {$ifdef VER36PRO} if parentreport.Exporting then begin RTFImage := TQRImage.create(nil); rtfimage.FAutoSize := true; rtfmeta := TMetafile.Create; rtfmeta.height := round((range.rc.bottom-range.rc.top) *LogX/1440.0); rtfmeta.width := round((range.rc.Right-range.rc.left) *LogX/1440.0); metacanvas := TMetafilecanvas.Create( rtfmeta, qrprinter.Canvas.handle); expwid := round((range.rc.Right-range.rc.left) *LogX/1440.0); expht := round((range.rc.bottom-range.rc.top) *LogX/1440.0); range.hdc := metaCanvas.Handle; range.hdcTarget := metaCanvas.Handle; SetMapMode(range.hdc, MM_TEXT); range.rc := rect( 0, 0, expwid * 1440 div LogX, expht * 1440 div LogY); range.rcPage := rect( 0, 0, expwid * 1440 div LogX, 2*expht * 1440 div LogY); SendMessage(ARichEdit.Handle, EM_FORMATRANGE, 1, Longint(@Range)); // MUST free the canvas before the metafile has an image (thanks, Bill) metacanvas.free; rtfimage.FPicture.Assign( rtfMeta); // set up the image control export rtfimage.Size.Left := size.Left; rtfimage.Size.width := size.width; rtfimage.Size.top := size.top; rtfimage.Size.height := size.height; rtfimage.Width := round((range.rc.Right-range.rc.left) *LogX/1440.0); rtfimage.Height := round((range.rc.bottom-range.rc.top) *LogX/1440.0); TQRExportFilter(ParentReport.ExportFilter).acceptgraphic( qrprinter.XPos(OfsX + rtfimage.Size.Left), qrprinter.YPos(OfsY+ rtfimage.size.top ), rtfimage ); rtfimage.free; rtfMeta.free; end; {$endif} SetMapMode(ParentReport.QRPrinter.Canvas.Handle, OldMapMode); if PrintFinished then SendMessage(ARichEdit.Handle, EM_FORMATRANGE, 0, 0); end; |