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:
| procedure TRxCustomRichEdit.Print(const Caption: string; const Li,Ob,Re,Un: integer); //by SL var Range: TFormatRange; LastChar, MaxLen, LogX, LogY, OldMap: Integer; SaveRect : TRect; TextLenEx : TGetTextLengthEx; i, j : integer; begin FillChar(Range, SizeOf(TFormatRange), 0); with Printer, Range do begin Title := Caption; BeginDoc; hdc := Handle; hdcTarget := hdc; LogX := GetDeviceCaps(Handle, LOGPIXELSX); LogY := GetDeviceCaps(Handle, LOGPIXELSY); if IsRectEmpty(PageRect) then begin rc.left := Li; rc.top := Ob; rc.right := MulDiv(PageWidth,1440,LogX) - Re; rc.bottom := MulDiv(PageHeight,1440,LogY) - Un; end else begin rc.left := MulDiv(PageRect.Left,1440,LogX) - Li; rc.top := MulDiv(PageRect.Top,1440,LogY) - Ob; rc.right := MulDiv(PageRect.Right,1440,LogX) - Re; rc.bottom := MulDiv(PageRect.Bottom,1440,LogY) - Un; end; rcPage := rc; SaveRect := rc; LastChar := 0; if RichEditVersion >= 2 then begin with TextLenEx do begin flags := GTL_DEFAULT; codepage := CP_ACP; end; MaxLen := Perform(EM_GETTEXTLENGTHEX, WParam(@TextLenEx), 0); end else MaxLen := GetTextLen; chrg.cpMax := -1; { ensure printer DC is in text map mode } OldMap := SetMapMode(hdc, MM_TEXT); SendMessage(Self.Handle, EM_FORMATRANGE, 0, 0); { flush buffer } try repeat rc := SaveRect; chrg.cpMin := LastChar; LastChar := SendMessage(Self.Handle, EM_FORMATRANGE, 1, Longint(@Range)); if (LastChar < MaxLen) and (LastChar <> -1) then NewPage; until (LastChar >= MaxLen) or (LastChar = -1); EndDoc; finally SendMessage(Self.Handle, EM_FORMATRANGE, 0, 0); { flush buffer } SetMapMode(hdc, OldMap); { restore previous map mode } end; end; end; |