#1 2026-05-05 16:56:55

tfopc
Member
Registered: 2024-01-08
Posts: 50

PDF - Font assignment didn't not work anymore - Problem - StrIEqual

Hi ab,

Problem detected at...

function TPdfDocument.GetTrueTypeFontIndex(const AName: RawUtf8): integer;
begin
  if StrIEqual(pointer(fTrueTypeFontLastName), pointer(AName)) then

StrIEqual with inital empty "fTrueTypeFontLastName" result in true.

Is there a bug in StrIEqual?

if Str1 <> Str2 then
    if Str1 <> nil then
      if Str2 <> nil then
      begin
       ....
      end;
  result := true;

so the font-index stays at 0 and first system font is used.

Offline

#2 2026-05-05 17:14:54

tfopc
Member
Registered: 2024-01-08
Posts: 50

Re: PDF - Font assignment didn't not work anymore - Problem - StrIEqual

Claude said there is a bug ;-), so also StrIEqualW is affected.

One of the suggested fixes:

  if Str1 = Str2 then
  begin
    result := true;
    exit;
  end;
  
  if (Str1 = nil) or (Str2 = nil) then
  begin
    result := false;
    exit;
  end;
  
  ...

Offline

#3 2026-05-05 17:17:47

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 15,475
Website

Re: PDF - Font assignment didn't not work anymore - Problem - StrIEqual

Offline

#4 2026-05-05 17:26:34

tfopc
Member
Registered: 2024-01-08
Posts: 50

Re: PDF - Font assignment didn't not work anymore - Problem - StrIEqual

That was realy fast - thanks Arnaud!

Yes, that fixes the problem thanks. Maybe also add the claude suggested tests.

StrIEqual(nil, nil)        // true  
StrIEqual(nil, 'test')     // false 
StrIEqual('test', nil)     // false 
StrIEqual('Test', 'test')  // true 
StrIEqual('abc', 'xyz')    // false

Have a nice evening.

Offline

Board footer

Powered by FluxBB