MCPcopy
hub / github.com/chenglou/pretext / stepPreparedChunkLineGeometry

Function stepPreparedChunkLineGeometry

src/line-break.ts:787–1034  ·  view source on GitHub ↗
(
  prepared: PreparedLineBreakData,
  cursor: LineBreakCursor,
  chunkIndex: number,
  maxWidth: number,
)

Source from the content-addressed store, hash-verified

785}
786
787function stepPreparedChunkLineGeometry(
788 prepared: PreparedLineBreakData,
789 cursor: LineBreakCursor,
790 chunkIndex: number,
791 maxWidth: number,
792): number | null {
793 const chunk = prepared.chunks[chunkIndex]!
794 if (chunk.startSegmentIndex === chunk.endSegmentIndex) {
795 cursor.segmentIndex = chunk.consumedEndSegmentIndex
796 cursor.graphemeIndex = 0
797 return 0
798 }
799
800 const {
801 widths,
802 kinds,
803 breakableFitAdvances,
804 breakablePreferredBreaks,
805 discretionaryHyphenWidth,
806 } = prepared
807 const engineProfile = getEngineProfile()
808 const lineFitEpsilon = engineProfile.lineFitEpsilon
809 const fitLimit = maxWidth + lineFitEpsilon
810
811 const lineStartSegmentIndex = cursor.segmentIndex
812 const lineStartGraphemeIndex = cursor.graphemeIndex
813 let lineW = 0
814 let hasContent = false
815 let lineEndSegmentIndex = cursor.segmentIndex
816 let lineEndGraphemeIndex = cursor.graphemeIndex
817 let pendingBreakSegmentIndex = -1
818 let pendingBreakFitWidth = 0
819 let pendingBreakPaintWidth = 0
820 let pendingBreakKind: SegmentBreakKind | null = null
821
822 function getCurrentLinePaintWidth(): number {
823 return (
824 pendingBreakKind === 'soft-hyphen' &&
825 pendingBreakSegmentIndex === lineEndSegmentIndex &&
826 lineEndGraphemeIndex === 0
827 )
828 ? pendingBreakPaintWidth
829 : lineW
830 }
831
832 function finishLine(
833 endSegmentIndex = lineEndSegmentIndex,
834 endGraphemeIndex = lineEndGraphemeIndex,
835 width = getCurrentLinePaintWidth(),
836 ): number | null {
837 if (!hasContent) return null
838 cursor.segmentIndex = endSegmentIndex
839 cursor.graphemeIndex = endGraphemeIndex
840 return finalizeLinePaintWidth(
841 prepared,
842 width,
843 lineStartSegmentIndex,
844 lineStartGraphemeIndex,

Callers 2

Calls 13

getEngineProfileFunction · 0.85
breaksAfterFunction · 0.85
getLeadingLetterSpacingFunction · 0.85
getTabAdvanceFunction · 0.85
startLineAtSegmentFunction · 0.85
finishLineFunction · 0.85
maybeFinishAtSoftHyphenFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…