PDFium Delphi Component Docs

LinkZOrderAt method

Component: TPdfView  ·  Unit: PDFium
Returns the stacking order of the topmost link annotation hit at the view pixel (X, Y), or -1

Syntax

function LinkZOrderAt(X, Y: Integer): Integer;

Parameters

X, YInteger. Pixel coordinates relative to the viewer control, i.e. the coordinates the mouse events receive

Return Value

Integer. The z-order of the link at the hit-tested point, or -1 when no link is hit or the test cannot be run

Description

Hit-tests a screen pixel against the native link annotations of the current page and reports the stacking position of the topmost one. The viewer converts (X, Y) to page-space coordinates with DeviceToPage, honouring Zoom, Rotation, display mode, page padding and scroll offset, then calls PDFium's FPDFLink_GetLinkZOrderAtPoint on the page handle, the same native point test used by LinkAnnotationAtPos

A larger return value means the link is stacked closer to the viewer, that is, drawn above links with smaller values. Z-order here is the topmost hit-testing order of the annotation stack, not a link index, so treat the values as opaque comparison numbers

The test queries the page directly and needs no form environment, so it works even when the document carries no AcroForm and is not gated by AllowFormEvents. Where a link and a form widget overlap, compare this result with FormFieldZOrderAt: the higher value identifies the annotation that PDFium treats as the hit at that pixel

The TPdf counterpart TPdf.LinkZOrderAtPoint(X, Y: Double) wraps the same PDFium function. It takes page-space coordinates in Double directly and raises an exception when no page is active, whereas the TPdfView wrapper fails soft and returns -1

Remarks

Example

procedure TForm1.PdfView1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  FieldZ, LinkZ: Integer;
begin
  FieldZ := PdfView1.FormFieldZOrderAt(X, Y);
  LinkZ := PdfView1.LinkZOrderAt(X, Y);
  if (LinkZ >= 0) and (LinkZ > FieldZ) then
    Caption := 'link wins the hit';
end;

See Also

FormFieldZOrderAt, LinkAnnotationAtPos, WebLinkAtPos, DeviceToPage