AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

"Echte" Ausmaße eines Strings ermitteln

Ein Thema von BigAl · begonnen am 11. Mär 2014 · letzter Beitrag vom 11. Mär 2014
 
Popov
(Gast)

n/a Beiträge
 
#6

AW: "Echte" Ausmaße eines Strings ermitteln

  Alt 11. Mär 2014, 16:12
Wenn dich noch Unterlänge stört (also alles was unter der Grundlinie liegt, wie bei Buchstaben wie g, j, p, usw.), kannst du mit SetTextAlign etwas experimentieren. Zwar gibt es hier keinen direkten Wert, aber durch Wechsel zwischen TA_BASELINE, TA_BOTTOM, TA_TOP und etwas Subtraktion, kann man grob die Höhe über Grundline und die darunter ermitteln.

Will man mehr über den aktuellen Font erfahren, u. a. weil man z. B. den Ascent oder Descent wissen will, kann man das mit GetTextMetrics machen:

http://upload.wikimedia.org/wikipedi..._Terms.svg.png

Delphi-Quellcode:
var
  Metrics: TTextMetric;
  s: String;
begin
  Canvas.Font.Name := 'Arial';
  Canvas.Font.Size := 28;

  if GetTextMetrics(Canvas.Handle, Metrics) then
  //GetTextMetrics(DC: HDC; var Metrics: TTextMetric): Bool;
  begin
    s := 'Texthöhe nach Delphi: ' + IntToStr(Canvas.TextHeight('X')) + ^j^j;

    with Metrics do
    begin
      s := s + 'tmHeight: ' + IntToStr(tmHeight) + ^j;
      s := s + 'tmAscent: ' + IntToStr(tmAscent) + ^j;
      s := s + 'tmDescent: ' + IntToStr(tmDescent) + ^j;
      s := s + 'tmInternalLeading: ' + IntToStr(tmInternalLeading) + ^j;
      s := s + 'tmExternalLeading: ' + IntToStr(tmExternalLeading) + ^j;
      s := s + 'tmAveCharWidth: ' + IntToStr(tmAveCharWidth) + ^j;
      s := s + 'tmMaxCharWidth: ' + IntToStr(tmMaxCharWidth) + ^j;
      s := s + 'tmWeight: ' + IntToStr(tmWeight) + ^j;
      s := s + 'tmOverhang: ' + IntToStr(tmOverhang) + ^j;
      s := s + 'tmDigitizedAspectX: ' + IntToStr(tmDigitizedAspectX) + ^j;
      s := s + 'tmDigitizedAspectY: ' + IntToStr(tmDigitizedAspectY) + ^j;
      s := s + 'tmItalic: ' + IntToStr(tmItalic) + ^j;
      s := s + 'tmUnderlined: ' + IntToStr(tmUnderlined) + ^j;
      s := s + 'tmStruckOut: ' + IntToStr(tmStruckOut) + ^j;
      s := s + 'tmPitchAndFamily: ' + IntToStr(tmPitchAndFamily) + ^j;
      s := s + 'tmCharSet: ' + IntToStr(tmCharSet) + ^j;
      s := s + 'tmFirstChar: "' + tmFirstChar + '"' + ^j;
      s := s + 'tmLastChar: "' + tmLastChar + '"' + ^j;
      s := s + 'tmDefaultChar: "' + tmDefaultChar + '"' + ^j;
      s := s + 'tmBreakChar: "' + tmBreakChar + '"' + ^j;
    end;

    ShowMessage(s);
  end
  else
    MessageDlg('Ach herrje, ein Fehler!', mtError, [mbOk], 0);
end;

Geändert von Popov (11. Mär 2014 um 16:22 Uhr)
  Mit Zitat antworten Zitat
 

 

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:00 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