기술 문서

PDFium Component: Delphi에서 word tracking and speech cursoring

Delphi와 C++Builder 애플리케이션에는 PDFium VCL Component 워크플로를, Lazarus/FPC에는 PDFium LCL Component 워크플로를 통합하여 보기, 렌더링, 폼, 인쇄, 프리플라이트 보고서, 표준 중심 검증을 소스 코드 컴포넌트로 구현할 수 있습니다.

이 글은 developers building read-aloud, study, review, or assisted-reading features Delphi에서 PDF viewers을 위한 글입니다. word tracking and speech cursoring을 단순한 컴포넌트 호출이 아니라 운영 환경의 문서 엔지니어링으로 다룹니다.

실제 위험은 speech highlighting becomes distracting or wrong when word boxes, ligatures, rotation, hidden text, and timing do not match the spoken stream입니다. 따라서 명확한 계약, 관찰 가능한 진단, 실제 고객 파일을 반영한 회귀 샘플이 필요합니다.

아키텍처 결정

Synchronize speech with extracted text, not pixels alone. text extraction source, word segmentation policy, and language assumptions / highlight style, scroll behavior, pause and resume rules, and user controls

  • text extraction source, word segmentation policy, and language assumptions
  • highlight style, scroll behavior, pause and resume rules, and user controls
  • fallback behavior for image-only pages, hidden text, ligatures, and rotated content
  • whether speech timing is driven by the engine, the viewer, or a shared coordinator

구현 흐름

Track words through a stable text map. The order below keeps the workflow reviewable for Delphi and C++Builder teams.

  1. extract page text and word bounds before speech playback begins
  2. build a word map that links text offsets, page numbers, and viewer coordinates
  3. call the tracking layer as the speech engine advances through words or offsets
  4. scroll the viewport only when the current word leaves the comfortable reading zone
  5. record skipped words, missing boxes, and timing drift for diagnostics

검증 증거

Synchronization evidence for assisted reading. Keep these fields with the output or support record.

  • page number, word text, text offset, bounding box, and speech timestamp
  • tracking method used, including TrackReadingWordAt when the viewer supports it
  • fallback reason for words without reliable geometry
  • latency between speech event and visible cursor update

Word boxes are viewer data

Word-synchronized reading needs a mapping between extracted text, page coordinates, and speech timing. A robust implementation knows when text is unavailable, when a word box is ambiguous, and how to keep the viewport aligned with the current spoken word.

출시 전 확인 사항

이 항목이 프로덕션에 도달하기 전에 팀은 소스 코드를 읽지 않고도 이 질문들에 답할 수 있어야 합니다

  • Who owns text extraction source, word segmentation policy, and language assumptions?
  • What evidence proves page number, word text, text offset, bounding box, and speech timestamp?
  • What happens when ligatures can represent multiple characters inside one visual glyph?
  • Which regression file covers record skipped words, missing boxes, and timing drift for diagnostics?

word tracking and speech cursoring에 대한 엔지니어링 검토 노트

이 검토 노트를 사용해 기능이 데모 단계를 넘어섰고 출시, 지원, 고객 에스컬레이션 상황에서 설명할 수 있는지 확인합니다

  • 결정: text extraction source, word segmentation policy, and language assumptions. 구현상 핵심 지점: build a word map that links text offsets, page numbers, and viewer coordinates. 승인 증거: fallback reason for words without reliable geometry. 회귀 트리거: rapid speech rates can require coalescing highlight updates to avoid flicker
  • 결정: highlight style, scroll behavior, pause and resume rules, and user controls. 구현상 핵심 지점: call the tracking layer as the speech engine advances through words or offsets. 승인 증거: latency between speech event and visible cursor update. 회귀 트리거: ligatures can represent multiple characters inside one visual glyph
  • 결정: fallback behavior for image-only pages, hidden text, ligatures, and rotated content. 구현상 핵심 지점: scroll the viewport only when the current word leaves the comfortable reading zone. 승인 증거: page number, word text, text offset, bounding box, and speech timestamp. 회귀 트리거: rotated or vertical text needs coordinate handling separate from normal pages

경계 사례

  • ligatures can represent multiple characters inside one visual glyph
  • rotated or vertical text needs coordinate handling separate from normal pages
  • OCR text layers may not align perfectly with scanned images
  • rapid speech rates can require coalescing highlight updates to avoid flicker

Delphi / C++Builder 참고 사항

PDFium Component should sit behind a small service boundary that receives files, streams, profiles, and credentials, then returns output paths, warnings, metrics, and validation status. 중요한 용어는 TrackReadingWordAt, speech cursor, word bounds, text extraction, highlight, reading assistance.

Delphi 코드 예제

다음 Delphi 스케치는 이 주제에 맞는 실무형 서비스 경계를 보여 줍니다. 정책 검사, 로깅, 검증을 좁은 제품 호출 구간 밖에 두면 워크플로를 테스트하기 쉽습니다.

procedure TSpeechForm.SpeakWordAtCursor(PageNo, CharIndex: Integer);
var
  UnitInfo: TReadingUnit;
begin
  UnitInfo := LocateWordUnit(PdfView, PageNo, CharIndex);
  HighlightBounds(UnitInfo.PageNo, UnitInfo.Bounds);
  SpeechQueue.Speak(UnitInfo.Text);
  StoreCursorPosition(UnitInfo.PageNo, UnitInfo.EndChar);
end;

운영 체크리스트

  • 워크플로는 빈 파일, 일반 고객 파일, 최악의 파일에서 실행합니다
  • 생성된 PDF는 대상 뷰어, 검증기, 프린터 또는 downstream 애플리케이션에서 엽니다
  • 제품 버전, 프로필 버전, 입력 해시, 출력 경로, 경과 시간, 경고 수를 기록합니다
  • 암호, 인증서, 임시 파일, 고객 데이터는 명확한 보존 규칙에 따라 관리합니다
  • 고객 파일이 새로운 경계 사례를 드러내면 회귀 문서를 추가합니다

제품 문서

PDFium Component

추가 코드 예제

procedure TReaderForm.OnSpeechWordBoundary(StreamPos: Integer);
var
  WordIdx: Integer;
begin
  // Maps the offset to a word box and moves the highlight in one call
  WordIdx := PdfView.TrackReadingWordAt(FPageNo, StreamPos);
  if WordIdx < 0 then
    Exit;                     // boundary fell outside any word: keep last highlight
end;
procedure TReaderForm.StopReading;
begin
  FVoice.Stop;                // halt SAPI playback first
  PdfView.ClearReadingWord;   // then remove the highlight; a stale cursor reads as a bug
end;