improved gtk intf to calculate TextHeight

git-svn-id: trunk@6625 -
This commit is contained in:
mattias 2005-01-17 15:36:31 +00:00
parent a2b5b0b52e
commit a21cbfceca
5 changed files with 76 additions and 38 deletions

View File

@ -8704,8 +8704,11 @@ const
ItalicStyles: array[boolean] of TFontStyles = ([], [fsItalic]); ItalicStyles: array[boolean] of TFontStyles = ([], [fsItalic]);
begin begin
with fTextDrawer do begin with fTextDrawer do begin
//debugln('TCustomSynEdit.RecalcCharExtent A UseUTF8=',dbgs(UseUTF8),
// ' Font.CanUTF8='+dbgs(Font.CanUTF8)+' CharHeight=',dbgs(CharHeight));
BaseFont := Self.Font; BaseFont := Self.Font;
BaseStyle := ItalicStyles[UsesFontStyle(fsItalic)]; BaseStyle := ItalicStyles[UsesFontStyle(fsItalic)];
//debugln('TCustomSynEdit.RecalcCharExtent B CharHeight=',dbgs(CharHeight));
fTextHeight := CharHeight + fExtraLineSpacing; fTextHeight := CharHeight + fExtraLineSpacing;
BaseStyle := BoldStyles[UsesFontStyle(fsBold)]; BaseStyle := BoldStyles[UsesFontStyle(fsBold)];
fCharWidth := CharWidth; fCharWidth := CharWidth;

View File

@ -71,7 +71,7 @@ interface
uses uses
{$IFDEF SYN_LAZARUS} {$IFDEF SYN_LAZARUS}
LCLIntf, LCLType, GraphType, LCLProc, LCLType, LCLIntf, GraphType,
{$ELSE} {$ELSE}
Windows, Windows,
{$ENDIF} {$ENDIF}
@ -581,13 +581,17 @@ var
ABC2: TABC; ABC2: TABC;
w: Integer; w: Integer;
HasABC: Boolean; HasABC: Boolean;
//Size: TSize;
begin begin
// Calculate advance of a character. // Calculate advance of a character.
// The following code uses ABC widths instead TextMetric.tmAveCharWidth // The following code uses ABC widths instead TextMetric.tmAveCharWidth
// because ABC widths always tells truth but tmAveCharWidth does not. // 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 // A true-type font will have ABC widths but others like raster type will not
// so if the function fails then use TextMetric.tmAveCharWidth. // so if the function fails then use TextMetric.tmAveCharWidth.
//debugln('TheFontStock.CalcFontAdvance A ',dbgs(pCharHeight));
GetTextMetrics(DC, TM); 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} {$IFDEF FPC}
// the next two lines are only to suppress the stupid FPC warnings: // the next two lines are only to suppress the stupid FPC warnings:
ABC.abcA:=0; ABC.abcA:=0;

View File

@ -343,6 +343,16 @@ var i, j, FilenameEndPos: integer;
end; end;
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; function CheckForNumber(const Str: string; var p: integer): boolean;
var var
OldP: Integer; OldP: Integer;
@ -385,6 +395,9 @@ begin
// check for 'Fatal: ', 'Panic: ', 'Error: ', 'Closing script ppas.sh' // check for 'Fatal: ', 'Panic: ', 'Error: ', 'Closing script ppas.sh'
Result:=CheckForUrgentMessages; Result:=CheckForUrgentMessages;
if Result then exit; if Result then exit;
// check for 'Note: '
Result:=CheckForNoteMessages;
if Result then exit;
// check for '<line> <kb>/<kb> Kb Free' // check for '<line> <kb>/<kb> Kb Free'
Result:=CheckForLineProgress; Result:=CheckForLineProgress;
if Result then exit; if Result then exit;

View File

@ -6359,22 +6359,22 @@ begin
IsDoubleByteChar:=FontIsDoubleByteCharsFont(UseFont); IsDoubleByteChar:=FontIsDoubleByteCharsFont(UseFont);
AvgTxtLen:=length(TestString[false]); AvgTxtLen:=length(TestString[false]);
if IsDoubleByteChar then begin if IsDoubleByteChar then begin
gdk_text_extents_wc(UseFont, PGdkWChar(TestString[IsDoubleByteChar]), gdk_text_extents(UseFont, PChar(TestString[IsDoubleByteChar]),
AvgTxtLen*2, @lBearing, @rBearing, @Width, AvgTxtLen*2, @lBearing, @rBearing, @Width,
@TextMetric.tmAscent, @TextMetric.tmDescent); @TextMetric.tmAscent, @TextMetric.tmDescent);
//debugln('TGtkWidgetSet.UpdateDCTextMetric A IsDoubleByteChar=',dbgs(IsDoubleByteChar),' Width=',dbgs(Width),' AvgTxtLen=',dbgs(AvgTxtLen)); //debugln('TGtkWidgetSet.UpdateDCTextMetric A IsDoubleByteChar=',dbgs(IsDoubleByteChar),' Width=',dbgs(Width),' AvgTxtLen=',dbgs(AvgTxtLen));
TextMetric.tmHeight := gdk_text_height(UseFont, TextMetric.tmHeight := TextMetric.tmAscent+TextMetric.tmDescent;
PChar(TestString[IsDoubleByteChar]), // gdk_text_height(UseFont,PChar(TestString[IsDoubleByteChar]),
AvgTxtLen*2) // AvgTxtLen*2)
{$IfNDef Win32} + TextMetric.tmdescent div 2{$EndIf}; // {$IfNDef Win32} + TextMetric.tmdescent div 2{$EndIf};
end else begin end else begin
gdk_text_extents(UseFont, PChar(TestString[IsDoubleByteChar]), gdk_text_extents(UseFont, PChar(TestString[IsDoubleByteChar]),
AvgTxtLen, @lBearing, @rBearing, @Width, AvgTxtLen, @lBearing, @rBearing, @Width,
@TextMetric.tmAscent, @TextMetric.tmDescent); @TextMetric.tmAscent, @TextMetric.tmDescent);
TextMetric.tmHeight := gdk_text_height(UseFont, TextMetric.tmHeight := TextMetric.tmAscent+TextMetric.tmDescent;
PChar(TestString[IsDoubleByteChar]), // gdk_text_height(UseFont,PChar(TestString[IsDoubleByteChar]),
AvgTxtLen) // AvgTxtLen)
{$IfNDef Win32} + TextMetric.tmdescent div 2{$EndIf}; // {$IfNDef Win32} + TextMetric.tmdescent div 2{$EndIf};
end; end;
//if Width<AvgTxtLen then UseWidthHeuristic; //if Width<AvgTxtLen then UseWidthHeuristic;
//TextMetric.tmAscent := TextMetric.tmHeight - TextMetric.tmDescent; //TextMetric.tmAscent := TextMetric.tmHeight - TextMetric.tmDescent;
@ -6385,14 +6385,14 @@ begin
gdk_char_width(UseFont, 'M')); // temp hack gdk_char_width(UseFont, 'M')); // temp hack
if TextMetric.tmMaxCharWidth<TextMetric.tmAveCharWidth then if TextMetric.tmMaxCharWidth<TextMetric.tmAveCharWidth then
TextMetric.tmMaxCharWidth:=TextMetric.tmAveCharWidth; TextMetric.tmMaxCharWidth:=TextMetric.tmAveCharWidth;
{debugln('TGtkWidgetSet.UpdateDCTextMetric A IsDoubleByteChar=',dbgs(IsDoubleByteChar), //debugln('TGtkWidgetSet.UpdateDCTextMetric A IsDoubleByteChar=',dbgs(IsDoubleByteChar),
' lbearing=',dbgs(lBearing),' rbearing=',dbgs(rBearing), // ' lbearing=',dbgs(lBearing),' rbearing=',dbgs(rBearing),
' width='+dbgs(width),' tmAscent='+dbgs(TextMetric.tmAscent), // ' width='+dbgs(width),' tmAscent='+dbgs(TextMetric.tmAscent),
' tmDescent='+dbgs(TextMetric.tmdescent), // ' tmDescent='+dbgs(TextMetric.tmdescent),
' tmHeight='+dbgs(TextMetric.tmHeight), // ' tmHeight='+dbgs(TextMetric.tmHeight),
' AvgTxtLen='+dbgs(AvgTxtLen), // ' AvgTxtLen='+dbgs(AvgTxtLen),
' tmMaxCharWidth='+dbgs(TextMetric.tmMaxCharWidth), // ' tmMaxCharWidth='+dbgs(TextMetric.tmMaxCharWidth),
' tmAveCharWidth='+dbgs(TextMetric.tmAveCharWidth));} // ' tmAveCharWidth='+dbgs(TextMetric.tmAveCharWidth));
if (CachedFont<>nil) then begin if (CachedFont<>nil) then begin
CachedFont.lBearing:=lBearing; CachedFont.lBearing:=lBearing;
CachedFont.rBearing:=rBearing; CachedFont.rBearing:=rBearing;
@ -6994,6 +6994,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $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 Revision 1.616 2005/01/12 23:18:07 mattias
limited widget sizes to 10000x10000 limited widget sizes to 10000x10000

View File

@ -1347,7 +1347,8 @@ var
end; end;
{$IFDEF VerboseFonts} {$IFDEF VerboseFonts}
DebugLn(' Tried "',S,'" Success=',dbgs(GdiObject^.GDIFontObject<>nil)); //if GdiObject^.GDIFontObject<>nil then
DebugLn(' Tried "',S,'" Success=',dbgs(GdiObject^.GDIFontObject<>nil));
{$ENDIF} {$ENDIF}
end; end;
@ -1368,6 +1369,13 @@ var
if Result='' then Result:='*'; if Result='' then Result:='*';
end; end;
function ExtractXLFDItemMask(const ALongFontName: string;
Index: Integer): string;
begin
Result:=ExtractXLFDItem(ALongFontName,Index);
if Result='' then Result:='*';
end;
function FamilyNameExists: boolean; function FamilyNameExists: boolean;
var var
AFont: PGdkFont; AFont: PGdkFont;
@ -1442,21 +1450,21 @@ begin
,' ',dbgs(ord(LogFont.lfFaceName[0]))); ,' ',dbgs(ord(LogFont.lfFaceName[0])));
{$ENDIF} {$ENDIF}
if IsFontNameXLogicalFontDesc(LongFontName) then begin if IsFontNameXLogicalFontDesc(LongFontName) then begin
FontNameRegistry := ExtractXLFDItem(LongFontName,0); FontNameRegistry := ExtractXLFDItemMask(LongFontName,0);
Foundry := ExtractXLFDItem(LongFontName,1); Foundry := ExtractXLFDItemMask(LongFontName,1);
FamilyName := ExtractXLFDItem(LongFontName,2); FamilyName := ExtractXLFDItemMask(LongFontName,2);
WeightName := ExtractXLFDItem(LongFontName,3); WeightName := ExtractXLFDItemMask(LongFontName,3);
Slant := ExtractXLFDItem(LongFontName,4); Slant := ExtractXLFDItemMask(LongFontName,4);
SetWidthName := ExtractXLFDItem(LongFontName,5); SetWidthName := ExtractXLFDItemMask(LongFontName,5);
AddStyleName := ExtractXLFDItem(LongFontName,6); AddStyleName := ExtractXLFDItemMask(LongFontName,6);
PixelSize := ExtractXLFDItem(LongFontName,7); PixelSize := ExtractXLFDItemMask(LongFontName,7);
PointSize := ExtractXLFDItem(LongFontName,8); PointSize := ExtractXLFDItemMask(LongFontName,8);
ResolutionX := ExtractXLFDItem(LongFontName,9); ResolutionX := ExtractXLFDItemMask(LongFontName,9);
ResolutionY := ExtractXLFDItem(LongFontName,10); ResolutionY := ExtractXLFDItemMask(LongFontName,10);
Spacing := ExtractXLFDItem(LongFontName,11); Spacing := ExtractXLFDItemMask(LongFontName,11);
AverageWidth := ExtractXLFDItem(LongFontName,12); AverageWidth := ExtractXLFDItemMask(LongFontName,12);
CharSetRegistry := ExtractXLFDItem(LongFontName,13); CharSetRegistry := ExtractXLFDItemMask(LongFontName,13);
CharSetCoding := ExtractXLFDItem(LongFontName,14); CharSetCoding := ExtractXLFDItemMask(LongFontName,14);
end else if CheckFontNameIsMangledXLogicalFontDesc(LongFontName) then begin end else if CheckFontNameIsMangledXLogicalFontDesc(LongFontName) then begin
end; end;
@ -1471,12 +1479,12 @@ begin
FamilyName := StrPas(lfFaceName); //StringReplace(FaceName, ' ', '*'); FamilyName := StrPas(lfFaceName); //StringReplace(FaceName, ' ', '*');
if (AnsiCompareText(FamilyName,'default')<>0) if (CompareText(FamilyName,'default')<>0)
and (not FamilyNameExists) then begin and (not FamilyNameExists) then begin
FamilyName:='default'; FamilyName:='default';
end; end;
if AnsiCompareText(FamilyName,'default')=0 then begin if CompareText(FamilyName,'default')=0 then begin
{$IFDEF VerboseFonts} {$IFDEF VerboseFonts}
DebugLn('TGtkWidgetSet.CreateFontIndirectEx FamilyName="',FamilyName,'" PixelSize=',PixelSize,' LogFont.lfHeight=',LogFont.lfHeight); DebugLn('TGtkWidgetSet.CreateFontIndirectEx FamilyName="',FamilyName,'" PixelSize=',PixelSize,' LogFont.lfHeight=',LogFont.lfHeight);
{$ENDIF} {$ENDIF}
@ -5450,8 +5458,12 @@ begin
end; end;
Size.cX := Width; Size.cX := Width;
// I THINK this is accurate... // I THINK this is accurate...
Size.cY := GDK_String_Height(UseFont, Str) Size.cY :={$IFDEF Win32}
{$IfNDef Win32} + descent div 2{$EndIf}; 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 If UnRef then
FontCache.Unreference(UseFont); FontCache.Unreference(UseFont);
end; end;
@ -8840,6 +8852,9 @@ end;
{ ============================================================================= { =============================================================================
$Log$ $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 Revision 1.385 2005/01/16 11:40:11 mattias
fixed TGtkWidgetSet.ExtSelectClipRGN for DCOrigin fixed TGtkWidgetSet.ExtSelectClipRGN for DCOrigin