@@ -1761,6 +1761,7 @@ ThtDocument = class(TCell) {a list of all the sections -- the html document}
17611761 procedure SetBackgroundImage(const Name: ThtString; const APrec: PtPositionRec);
17621762 procedure SetFormControlData(FormData: TFormData);
17631763 procedure SetYOffset(Y: Integer);
1764+ procedure AddGDILinkComment(AHandle: HDC; const AUrl: ThtString; const ARect: TRect);
17641765 procedure SetFonts(const Name, PreName: ThtString; ASize: Integer;
17651766 AColor, AHotSpot, AVisitedColor, AActiveColor, ABackground: TColor; LnksActive, LinkUnderLine: Boolean;
17661767 ACodePage: TBuffCodePage; ACharSet: TFontCharSet; MarginHeight, MarginWidth: Integer);
@@ -2552,6 +2553,8 @@ procedure TFontObj.ConvertFont(const FI: ThtFontInfo);
25522553end;
25532554
25542555constructor TFontObj.CreateCopy(ASection: TSection; T: TFontObj);
2556+ var
2557+ LOriginalSize: Integer;
25552558begin
25562559 inherited Create;
25572560{$ifndef NoTabLink}
@@ -2561,8 +2564,13 @@ constructor TFontObj.CreateCopy(ASection: TSection; T: TFontObj);
25612564 SScript := T.SScript;
25622565 TheFont := ThtFont.Create;
25632566 TheFont.Assign(T.TheFont);
2567+ LOriginalSize := TheFont.Size; // Save original size before ConvertFont
25642568 if Assigned(T.FIArray) then
25652569 ConvertFont(T.FIArray.Ar[LFont]);
2570+ // Fix: restore font size if ConvertFont set it to 0 (happens with links)
2571+ // This ensures link text is rendered in PDF export via MakePagedMetaFiles
2572+ if (TheFont.Size = 0) and (LOriginalSize <> 0) then
2573+ TheFont.Size := LOriginalSize;
25662574 UrlTarget := TUrlTarget.Create;
25672575 UrlTarget.Assign(T.UrlTarget);
25682576 FontChanged;
@@ -3497,7 +3505,7 @@ procedure TImageObj.DrawInline(Canvas: TCanvas; X, Y, YBaseline: Integer; FO: TF
34973505 end;
34983506
34993507 if (Assigned(MyFormControl) and MyFormControl.Active or FO.Active) or
3500- IsCopy and Assigned(Document.LinkDrawnEvent) and ( FO.UrlTarget.Url <> '')
3508+ ( IsCopy and ( FO.UrlTarget.Url <> '') )
35013509 then
35023510 with Canvas do
35033511 begin
@@ -3517,8 +3525,15 @@ procedure TImageObj.DrawInline(Canvas: TCanvas; X, Y, YBaseline: Integer; FO: TF
35173525 Canvas.DrawFocusRect(ARect); {draw focus box}
35183526 end
35193527 else
3520- Document.LinkDrawnEvent(Document.TheOwner, Document.LinkPage,
3521- FO.UrlTarget.Url, FO.UrlTarget.Target, ARect);
3528+ begin
3529+ // When IsCopy is true (PDF export via MakePagedMetaFiles), insert a GDI comment
3530+ // that SynPDF will interpret as a hyperlink annotation
3531+ if FO.UrlTarget.Url <> '' then
3532+ Document.AddGDILinkComment(Canvas.Handle, FO.UrlTarget.Url, ARect);
3533+ if Assigned(Document.LinkDrawnEvent) then
3534+ Document.LinkDrawnEvent(Document.TheOwner, Document.LinkPage,
3535+ FO.UrlTarget.Url, FO.UrlTarget.Target, ARect);
3536+ end;
35223537 SetTextColor(handle, SaveColor);
35233538 end;
35243539end;
@@ -7590,6 +7605,41 @@ procedure ThtDocument.SetYOffset(Y: Integer);
75907605 HideControls;
75917606end;
75927607
7608+ //------------------------------------------------------------------------------
7609+ // AddGDILinkComment - Inserts a GDI comment into the metafile canvas that
7610+ // SynPDF will interpret as a hyperlink annotation during PDF export.
7611+ // The comment format is compatible with SynPDF's pgcLink/pgcLinkNoBorder.
7612+ //------------------------------------------------------------------------------
7613+ procedure ThtDocument.AddGDILinkComment(AHandle: HDC; const AUrl: ThtString;
7614+ const ARect: TRect);
7615+ const
7616+ pgcLinkNoBorder: Byte = 3; // from SynPdf.pas TPdfGDIComment enumeration
7617+ var
7618+ LUrl: RawByteString;
7619+ LData: RawByteString;
7620+ LLen, LTotalLen: Integer;
7621+ D: PAnsiChar;
7622+ begin
7623+ // Convert URL to UTF8 for SynPDF compatibility
7624+ LUrl := UTF8Encode(AUrl);
7625+ LLen := Length(LUrl);
7626+ // Format: 1 byte (link type) + SizeOf(TRect) bytes (rectangle) + URL bytes
7627+ LTotalLen := 1 + SizeOf(TRect) + LLen;
7628+ SetLength(LData, LTotalLen);
7629+ D := PAnsiChar(LData);
7630+ // pgcLinkNoBorder = 3 (no visible border around the link in PDF)
7631+ D^ := AnsiChar(pgcLinkNoBorder);
7632+ Inc(D);
7633+ // Copy rectangle
7634+ PRect(D)^ := ARect;
7635+ Inc(D, SizeOf(TRect));
7636+ // Copy URL
7637+ if LLen > 0 then
7638+ System.Move(Pointer(LUrl)^, D^, LLen);
7639+ // Insert GDI comment into the metafile
7640+ GdiComment(AHandle, LTotalLen, Pointer(LData));
7641+ end;
7642+
75937643//-- BG ---------------------------------------------------------- 08.01.2023 --
75947644function ThtDocument.ThemedColor(AColor: TColor; AStyleElement: ThtStyleElement): TColor;
75957645begin
@@ -13799,6 +13849,10 @@ function TSection.Draw1(Canvas: TCanvas; const ARect: TRect;
1379913849 if Document.TheOwner.ShowFocusRect then //MK20091107
1380013850 Canvas.DrawFocusRect(ARect);
1380113851 end;
13852+ // When IsCopy is true (PDF export via MakePagedMetaFiles), insert a GDI comment
13853+ // that SynPDF will interpret as a hyperlink annotation
13854+ if IsCopy and (FO.UrlTarget.Url <> '') then
13855+ Document.AddGDILinkComment(Canvas.Handle, FO.UrlTarget.Url, ARect);
1380213856 if Assigned(Document.LinkDrawnEvent) then
1380313857 Document.LinkDrawnEvent(Document.TheOwner, Document.LinkPage,
1380413858 FO.UrlTarget.Url, FO.UrlTarget.Target, ARect);
0 commit comments