mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-22 06:20:45 +02:00
improved gtk intf to calculate TextHeight
git-svn-id: trunk@6625 -
This commit is contained in:
parent
a2b5b0b52e
commit
a21cbfceca
@ -8704,8 +8704,11 @@ const
|
||||
ItalicStyles: array[boolean] of TFontStyles = ([], [fsItalic]);
|
||||
begin
|
||||
with fTextDrawer do begin
|
||||
//debugln('TCustomSynEdit.RecalcCharExtent A UseUTF8=',dbgs(UseUTF8),
|
||||
// ' Font.CanUTF8='+dbgs(Font.CanUTF8)+' CharHeight=',dbgs(CharHeight));
|
||||
BaseFont := Self.Font;
|
||||
BaseStyle := ItalicStyles[UsesFontStyle(fsItalic)];
|
||||
//debugln('TCustomSynEdit.RecalcCharExtent B CharHeight=',dbgs(CharHeight));
|
||||
fTextHeight := CharHeight + fExtraLineSpacing;
|
||||
BaseStyle := BoldStyles[UsesFontStyle(fsBold)];
|
||||
fCharWidth := CharWidth;
|
||||
|
@ -71,7 +71,7 @@ interface
|
||||
|
||||
uses
|
||||
{$IFDEF SYN_LAZARUS}
|
||||
LCLIntf, LCLType, GraphType,
|
||||
LCLProc, LCLType, LCLIntf, GraphType,
|
||||
{$ELSE}
|
||||
Windows,
|
||||
{$ENDIF}
|
||||
@ -581,13 +581,17 @@ var
|
||||
ABC2: TABC;
|
||||
w: Integer;
|
||||
HasABC: Boolean;
|
||||
//Size: TSize;
|
||||
begin
|
||||
// Calculate advance of a character.
|
||||
// The following code uses ABC widths instead TextMetric.tmAveCharWidth
|
||||
// because ABC widths always tells truth but tmAveCharWidth does not.
|
||||
// A true-type font will have ABC widths but others like raster type will not
|
||||
// so if the function fails then use TextMetric.tmAveCharWidth.
|
||||
//debugln('TheFontStock.CalcFontAdvance A ',dbgs(pCharHeight));
|
||||
GetTextMetrics(DC, TM);
|
||||
//GetTextExtentPoint(DC,'ABCgjp',6,Size);
|
||||
//debugln('TheFontStock.CalcFontAdvance B ',dbgs(pCharHeight),' TM.tmHeight=',dbgs(TM.tmHeight),' TM.tmAscent=',dbgs(TM.tmAscent),' TM.tmDescent=',dbgs(TM.tmDescent),' "',BaseFont.Name,'" ',dbgs(BaseFont.height),' ',dbgs(Size.cx),',',dbgs(Size.cy));
|
||||
{$IFDEF FPC}
|
||||
// the next two lines are only to suppress the stupid FPC warnings:
|
||||
ABC.abcA:=0;
|
||||
|
@ -343,6 +343,16 @@ var i, j, FilenameEndPos: integer;
|
||||
end;
|
||||
end;
|
||||
|
||||
function CheckForNoteMessages: boolean;
|
||||
begin
|
||||
Result:=false;
|
||||
if ('Note: '=copy(s,1,length('Note: '))) then begin
|
||||
DoAddFilteredLine(s);
|
||||
Result:=true;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
function CheckForNumber(const Str: string; var p: integer): boolean;
|
||||
var
|
||||
OldP: Integer;
|
||||
@ -385,6 +395,9 @@ begin
|
||||
// check for 'Fatal: ', 'Panic: ', 'Error: ', 'Closing script ppas.sh'
|
||||
Result:=CheckForUrgentMessages;
|
||||
if Result then exit;
|
||||
// check for 'Note: '
|
||||
Result:=CheckForNoteMessages;
|
||||
if Result then exit;
|
||||
// check for '<line> <kb>/<kb> Kb Free'
|
||||
Result:=CheckForLineProgress;
|
||||
if Result then exit;
|
||||
|
@ -6359,22 +6359,22 @@ begin
|
||||
IsDoubleByteChar:=FontIsDoubleByteCharsFont(UseFont);
|
||||
AvgTxtLen:=length(TestString[false]);
|
||||
if IsDoubleByteChar then begin
|
||||
gdk_text_extents_wc(UseFont, PGdkWChar(TestString[IsDoubleByteChar]),
|
||||
gdk_text_extents(UseFont, PChar(TestString[IsDoubleByteChar]),
|
||||
AvgTxtLen*2, @lBearing, @rBearing, @Width,
|
||||
@TextMetric.tmAscent, @TextMetric.tmDescent);
|
||||
//debugln('TGtkWidgetSet.UpdateDCTextMetric A IsDoubleByteChar=',dbgs(IsDoubleByteChar),' Width=',dbgs(Width),' AvgTxtLen=',dbgs(AvgTxtLen));
|
||||
TextMetric.tmHeight := gdk_text_height(UseFont,
|
||||
PChar(TestString[IsDoubleByteChar]),
|
||||
AvgTxtLen*2)
|
||||
{$IfNDef Win32} + TextMetric.tmdescent div 2{$EndIf};
|
||||
TextMetric.tmHeight := TextMetric.tmAscent+TextMetric.tmDescent;
|
||||
// gdk_text_height(UseFont,PChar(TestString[IsDoubleByteChar]),
|
||||
// AvgTxtLen*2)
|
||||
// {$IfNDef Win32} + TextMetric.tmdescent div 2{$EndIf};
|
||||
end else begin
|
||||
gdk_text_extents(UseFont, PChar(TestString[IsDoubleByteChar]),
|
||||
AvgTxtLen, @lBearing, @rBearing, @Width,
|
||||
@TextMetric.tmAscent, @TextMetric.tmDescent);
|
||||
TextMetric.tmHeight := gdk_text_height(UseFont,
|
||||
PChar(TestString[IsDoubleByteChar]),
|
||||
AvgTxtLen)
|
||||
{$IfNDef Win32} + TextMetric.tmdescent div 2{$EndIf};
|
||||
TextMetric.tmHeight := TextMetric.tmAscent+TextMetric.tmDescent;
|
||||
// gdk_text_height(UseFont,PChar(TestString[IsDoubleByteChar]),
|
||||
// AvgTxtLen)
|
||||
// {$IfNDef Win32} + TextMetric.tmdescent div 2{$EndIf};
|
||||
end;
|
||||
//if Width<AvgTxtLen then UseWidthHeuristic;
|
||||
//TextMetric.tmAscent := TextMetric.tmHeight - TextMetric.tmDescent;
|
||||
@ -6385,14 +6385,14 @@ begin
|
||||
gdk_char_width(UseFont, 'M')); // temp hack
|
||||
if TextMetric.tmMaxCharWidth<TextMetric.tmAveCharWidth then
|
||||
TextMetric.tmMaxCharWidth:=TextMetric.tmAveCharWidth;
|
||||
{debugln('TGtkWidgetSet.UpdateDCTextMetric A IsDoubleByteChar=',dbgs(IsDoubleByteChar),
|
||||
' lbearing=',dbgs(lBearing),' rbearing=',dbgs(rBearing),
|
||||
' width='+dbgs(width),' tmAscent='+dbgs(TextMetric.tmAscent),
|
||||
' tmDescent='+dbgs(TextMetric.tmdescent),
|
||||
' tmHeight='+dbgs(TextMetric.tmHeight),
|
||||
' AvgTxtLen='+dbgs(AvgTxtLen),
|
||||
' tmMaxCharWidth='+dbgs(TextMetric.tmMaxCharWidth),
|
||||
' tmAveCharWidth='+dbgs(TextMetric.tmAveCharWidth));}
|
||||
//debugln('TGtkWidgetSet.UpdateDCTextMetric A IsDoubleByteChar=',dbgs(IsDoubleByteChar),
|
||||
// ' lbearing=',dbgs(lBearing),' rbearing=',dbgs(rBearing),
|
||||
// ' width='+dbgs(width),' tmAscent='+dbgs(TextMetric.tmAscent),
|
||||
// ' tmDescent='+dbgs(TextMetric.tmdescent),
|
||||
// ' tmHeight='+dbgs(TextMetric.tmHeight),
|
||||
// ' AvgTxtLen='+dbgs(AvgTxtLen),
|
||||
// ' tmMaxCharWidth='+dbgs(TextMetric.tmMaxCharWidth),
|
||||
// ' tmAveCharWidth='+dbgs(TextMetric.tmAveCharWidth));
|
||||
if (CachedFont<>nil) then begin
|
||||
CachedFont.lBearing:=lBearing;
|
||||
CachedFont.rBearing:=rBearing;
|
||||
@ -6994,6 +6994,9 @@ end;
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.617 2005/01/17 15:36:31 mattias
|
||||
improved gtk intf to calculate TextHeight
|
||||
|
||||
Revision 1.616 2005/01/12 23:18:07 mattias
|
||||
limited widget sizes to 10000x10000
|
||||
|
||||
|
@ -1347,7 +1347,8 @@ var
|
||||
end;
|
||||
|
||||
{$IFDEF VerboseFonts}
|
||||
DebugLn(' Tried "',S,'" Success=',dbgs(GdiObject^.GDIFontObject<>nil));
|
||||
//if GdiObject^.GDIFontObject<>nil then
|
||||
DebugLn(' Tried "',S,'" Success=',dbgs(GdiObject^.GDIFontObject<>nil));
|
||||
{$ENDIF}
|
||||
end;
|
||||
|
||||
@ -1368,6 +1369,13 @@ var
|
||||
if Result='' then Result:='*';
|
||||
end;
|
||||
|
||||
function ExtractXLFDItemMask(const ALongFontName: string;
|
||||
Index: Integer): string;
|
||||
begin
|
||||
Result:=ExtractXLFDItem(ALongFontName,Index);
|
||||
if Result='' then Result:='*';
|
||||
end;
|
||||
|
||||
function FamilyNameExists: boolean;
|
||||
var
|
||||
AFont: PGdkFont;
|
||||
@ -1442,21 +1450,21 @@ begin
|
||||
,' ',dbgs(ord(LogFont.lfFaceName[0])));
|
||||
{$ENDIF}
|
||||
if IsFontNameXLogicalFontDesc(LongFontName) then begin
|
||||
FontNameRegistry := ExtractXLFDItem(LongFontName,0);
|
||||
Foundry := ExtractXLFDItem(LongFontName,1);
|
||||
FamilyName := ExtractXLFDItem(LongFontName,2);
|
||||
WeightName := ExtractXLFDItem(LongFontName,3);
|
||||
Slant := ExtractXLFDItem(LongFontName,4);
|
||||
SetWidthName := ExtractXLFDItem(LongFontName,5);
|
||||
AddStyleName := ExtractXLFDItem(LongFontName,6);
|
||||
PixelSize := ExtractXLFDItem(LongFontName,7);
|
||||
PointSize := ExtractXLFDItem(LongFontName,8);
|
||||
ResolutionX := ExtractXLFDItem(LongFontName,9);
|
||||
ResolutionY := ExtractXLFDItem(LongFontName,10);
|
||||
Spacing := ExtractXLFDItem(LongFontName,11);
|
||||
AverageWidth := ExtractXLFDItem(LongFontName,12);
|
||||
CharSetRegistry := ExtractXLFDItem(LongFontName,13);
|
||||
CharSetCoding := ExtractXLFDItem(LongFontName,14);
|
||||
FontNameRegistry := ExtractXLFDItemMask(LongFontName,0);
|
||||
Foundry := ExtractXLFDItemMask(LongFontName,1);
|
||||
FamilyName := ExtractXLFDItemMask(LongFontName,2);
|
||||
WeightName := ExtractXLFDItemMask(LongFontName,3);
|
||||
Slant := ExtractXLFDItemMask(LongFontName,4);
|
||||
SetWidthName := ExtractXLFDItemMask(LongFontName,5);
|
||||
AddStyleName := ExtractXLFDItemMask(LongFontName,6);
|
||||
PixelSize := ExtractXLFDItemMask(LongFontName,7);
|
||||
PointSize := ExtractXLFDItemMask(LongFontName,8);
|
||||
ResolutionX := ExtractXLFDItemMask(LongFontName,9);
|
||||
ResolutionY := ExtractXLFDItemMask(LongFontName,10);
|
||||
Spacing := ExtractXLFDItemMask(LongFontName,11);
|
||||
AverageWidth := ExtractXLFDItemMask(LongFontName,12);
|
||||
CharSetRegistry := ExtractXLFDItemMask(LongFontName,13);
|
||||
CharSetCoding := ExtractXLFDItemMask(LongFontName,14);
|
||||
end else if CheckFontNameIsMangledXLogicalFontDesc(LongFontName) then begin
|
||||
end;
|
||||
|
||||
@ -1471,12 +1479,12 @@ begin
|
||||
|
||||
FamilyName := StrPas(lfFaceName); //StringReplace(FaceName, ' ', '*');
|
||||
|
||||
if (AnsiCompareText(FamilyName,'default')<>0)
|
||||
if (CompareText(FamilyName,'default')<>0)
|
||||
and (not FamilyNameExists) then begin
|
||||
FamilyName:='default';
|
||||
end;
|
||||
|
||||
if AnsiCompareText(FamilyName,'default')=0 then begin
|
||||
if CompareText(FamilyName,'default')=0 then begin
|
||||
{$IFDEF VerboseFonts}
|
||||
DebugLn('TGtkWidgetSet.CreateFontIndirectEx FamilyName="',FamilyName,'" PixelSize=',PixelSize,' LogFont.lfHeight=',LogFont.lfHeight);
|
||||
{$ENDIF}
|
||||
@ -5450,8 +5458,12 @@ begin
|
||||
end;
|
||||
Size.cX := Width;
|
||||
// I THINK this is accurate...
|
||||
Size.cY := GDK_String_Height(UseFont, Str)
|
||||
{$IfNDef Win32} + descent div 2{$EndIf};
|
||||
Size.cY :={$IFDEF Win32}
|
||||
GDK_String_Height(UseFont, Str)
|
||||
{$ELSE}
|
||||
ascent+descent;
|
||||
{$ENDIF}
|
||||
//debugln('TGtkWidgetSet.GetTextExtentPoint END Str="'+DbgStr(Str)+'" Size=',dbgs(Size.cX),'x',dbgs(Size.cY),' ascent=',dbgs(ascent),' descent=',dbgs(descent),' tmDescent=',dbgs(TDeviceContext(DC).DCTextMetric.TextMetric.tmDescent));
|
||||
If UnRef then
|
||||
FontCache.Unreference(UseFont);
|
||||
end;
|
||||
@ -8840,6 +8852,9 @@ end;
|
||||
{ =============================================================================
|
||||
|
||||
$Log$
|
||||
Revision 1.386 2005/01/17 15:36:31 mattias
|
||||
improved gtk intf to calculate TextHeight
|
||||
|
||||
Revision 1.385 2005/01/16 11:40:11 mattias
|
||||
fixed TGtkWidgetSet.ExtSelectClipRGN for DCOrigin
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user