AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein Delphi Richtige Text länge ist nicht berechenbar
Thema durchsuchen
Ansicht
Themen-Optionen

Richtige Text länge ist nicht berechenbar

Ein Thema von venice2 · begonnen am 11. Nov 2020 · letzter Beitrag vom 16. Nov 2020
Antwort Antwort
hoika

Registriert seit: 5. Jul 2006
Ort: Magdeburg
8.277 Beiträge
 
Delphi 10.4 Sydney
 
#1

AW: Richtige Text länge ist nicht berechenbar

  Alt 12. Nov 2020, 05:09
Hallo,
und wie hast Du es hinbekommen?
Heiko
  Mit Zitat antworten Zitat
venice2
(Gast)

n/a Beiträge
 
#2

AW: Richtige Text länge ist nicht berechenbar

  Alt 12. Nov 2020, 16:50
Hallo,
und wie hast Du es hinbekommen?
Es macht nicht viel sinn es aufzuführen weil die Lösung über mehrere Ebenen erreicht wird.
Hier ist die neue Funktion die im weiteren verlauf auf mehrere andere Funktionen verzweigt. (mehrere Ebenen)

Delphi-Quellcode:
function DrawEllipsisText(WinHandle: HWND; DC: Hdc; Text: WideString; TextRect: TRect;
  ColrARGB: COLORREF; UseFont: WideString; UseSize: Single; FontStyle: TFontStyle;
  ShadowOffset: Single; UseStrFormat: integer; WordWrap: BOOL): GPSTATUS;
var
  Width: integer;
  Fam: GpFontFamily;
  TempFont: GpFont;
  Graphics: LONG_PTR;
  rectF: TGPRectF;
  rc: TRect;
  strFormat: Pointer;
  boundingBox, layoutRect: TGPRectF;
begin

  Result := GenericError;
  Graphics := 0;
  strFormat := nil;
  TempFont := nil;
  Fam := nil;

  try
    GdipCheck(GdipCreateFromHDC(DC, Graphics));
    GdipCheck(GdipCreateFontFamilyFromName(PWideChar(UseFont), nil, Fam));
    if assigned(Fam) then
    begin
      GdipCheck(GdipCreateFont(Fam, UseSize, FontStyle, 2, TempFont));
      if assigned(TempFont) then
      begin
        GdipCheck(GdipCreateStringFormat(0, 0, strFormat));

        FillChar(boundingBox, SizeOf(boundingBox), 0);
        FillChar(layoutRect, SizeOf(layoutRect), 0);

        GdipCheck(GdipMeasureString(Graphics, PWideChar(Text), length(Text), TempFont, @layoutRect,
            strFormat, @boundingBox, nil, nil));

        Width := (TextRect.Right - TextRect.Left);

        if boundingBox.Width > Width then
        begin
          rectF := MakeRect(TextRect.Left, TextRect.Top, Width, TextRect.Bottom);
          rc.Left := round(rectF.x);
          rc.Top := round(rectF.y);
          rc.Bottom := round(rectF.Height);
          rc.Right := round(rectF.Width);

          UseStrFormat := GD_Ellipsis;
          Result := GdipCheck(DrawTextToDC(DC, Text, rc, ColrARGB, UseFont, UseSize, FontStyle,
              ShadowOffset, UseStrFormat, nil, False, 0, True));
        end
        else
          Result := GdipCheck(DrawTextToDC(DC, Text, TextRect, ColrARGB, UseFont, UseSize, FontStyle,
              ShadowOffset, UseStrFormat, nil, False, 0, WordWrap));
      end;
    end;
  finally
    if Graphics <> 0 then
      GdipCheck(GdipDeleteGraphics(Graphics));
    if assigned(TempFont) then
      GdipCheck(GdipDeleteFont(TempFont));
    if assigned(Fam) then
      GdipCheck(GdipDeleteFontFamily(Fam));
    if assigned(strFormat) then
      GdipCheck(GdipDeleteStringFormat(strFormat));
  end;


end;
Die ist sehr genau und tut was sie soll.
Aufruf.
Delphi-Quellcode:
        if gM.title <> 'then
        begin
          SKAERO_GetCaptionXY(x, y);
          if WinHandle = GetForegroundWindow then
            Color := SKAERO_ACTIVECAPTION
          else
            Color := SKAERO_INACTIVECAPTION;

          SetRect(rc, x, y, gP.MainWidth -70, SKAERO_CAPTIONFONTHEIGHT + 4);
          GDIP_DrawEllipsisText(WinHandle, SrcDC, gM.title, rc, Color,
            SKAERO_CAPTIONFONT, SKAERO_CAPTIONFONTHEIGHT, FontStyleBoldItalic, -1, 0);
        end else
        SKAERO_SetCTLText(WinHandle, 'KVideo Player64');

Geändert von venice2 (12. Nov 2020 um 17:23 Uhr)
  Mit Zitat antworten Zitat
venice2
(Gast)

n/a Beiträge
 
#3

AW: Richtige Text länge ist nicht berechenbar

  Alt 16. Nov 2020, 06:42
Die länge von Ellipsis Text stimmt nun habe aber ein ähnliches weiteres Problem.
Ich Ownerdraw mein Edit Control mit GDI+ dazu übergebe ich folgende Parameter.

Delphi-Quellcode:
edInput.SetFont(SKAERO_PUSHBUTFONTSIZE, PWideChar(SKAERO_TEXTFONT),
  FontStyleBoldItalic, SKAERO_ACTIVECAPTION, SKAERO_INACTIVECAPTION,
  True, -1);
Danach konvertiere ich den GDI+ Font in einen HFont damit das Edit den gleichen Font hat wie der den ich zeichne. Stimmt soweit.

Delphi-Quellcode:
procedure TSkinEdit.SetFont(nPointSize: Integer; FontName: String; FontStyle: TFontStyle;
  AktForecolor, InAktForecolor: COLORREF; Shadow: Boolean; ShadowOffset: Single);
var
  Fam: GpFontFamily;
  Gpf: GpFont;
  Graphics: LONG_PTR;
  DC: HDC;
  lf: LOGFONTW;

begin
  Graphics := 0;
  Gpf := nil;
  Fam := nil;

  if Handle <> 0 then
  begin
    FShadow := Shadow;
    FShadowColor := ShadowColor;
    FShadowOffset := ShadowOffset;
    FAktForecolor := AktForecolor;
    FInAktForecolor := InAktForecolor;
    FPointSize := nPointSize;
    FFontName := FontName;
    FFontStyle := FontStyle;

    DC := GetDC(0);
    try
      if GdipCheck(GdipCreateFromHDC(DC, Graphics)) = OK then
      begin
        if GdipCheck(GdipCreateFontFamilyFromName(PWideChar(FFontName), nil, Fam)) = OK then
        begin
          if assigned(Fam) then
          begin
            GdipCheck(GdipCreateFont(Fam, FPointSize, FontStyle, 2, Gpf));
            if assigned(Gpf) then
            begin
              GdipCheck(GdipGetLogFontW(Gpf, Graphics, lf));
              _hfont := CreateFontIndirectW(lf);
              SendMessageW(Handle, WM_SETFONT, WPARAM(_hfont), 0);
            end;
          end;
        end;
      end;
    finally
      ReleaseDC(0, DC);
      if Graphics <> 0 then
        GdipCheck(GdipDeleteGraphics(Graphics));
      if assigned(Gpf) then
        GdipCheck(GdipDeleteFont(Gpf));
      if assigned(Fam) then
        GdipCheck(GdipDeleteFontFamily(Fam));
    end;
  end;
end;
Aber das Caret Offset ist nicht gleich Gezeichneter Font -> Edit Font.

Der blinkende Cursor ist immer ein paar Pixel daneben abhängig von dem was ich schreibe.
Wie kann ich das beheben?

Geändert von venice2 ( 1. Dez 2020 um 15:05 Uhr)
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:37 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz