expanded method

CPDFTextRange expanded({
  1. int before = 0,
  2. int after = 0,
})

Returns a new CPDFTextRange that expands the current range by the given number of characters before and after the original range.

If the before value causes the start position to be less than 0, it will automatically clamp the start to 0 and reduce the total length accordingly to avoid overflow.

Parameters:

  • before: The number of characters to include before the original range. Default is 0.
  • after: The number of characters to include after the original range. Default is 0.

Returns: A new CPDFTextRange instance with adjusted location and length.

Implementation

CPDFTextRange expanded({int before = 0, int after = 0}) {
  int newStart = location - before;
  int newLength = length + before + after;

  if (newStart < 0) {
    newLength += newStart;
    newStart = 0;
  }

  return CPDFTextRange(
    pageIndex: pageIndex,
    location: newStart,
    length: newLength,
  );
}