Skip to content

Commit

Permalink
Stop including line number information in various places
Browse files Browse the repository at this point in the history
Affects: #48
  • Loading branch information
io7m committed Dec 9, 2023
1 parent 58568ef commit 11e89ca
Show file tree
Hide file tree
Showing 18 changed files with 573 additions and 314 deletions.
Expand Up @@ -19,10 +19,11 @@
import com.io7m.jattribute.core.AttributeReadableType;
import com.io7m.jsycamore.api.layout.SyLayoutContextType;
import com.io7m.jsycamore.api.text.SyTextLineMeasuredType;
import com.io7m.jsycamore.api.text.SyTextLinePositioned;
import com.io7m.jsycamore.api.themes.SyThemeClassNameType;

import java.util.List;
import java.util.SortedMap;
import java.util.Optional;

import static com.io7m.jsycamore.api.themes.SyThemeClassNameStandard.TEXT_MULTILINE_VIEW;

Expand Down Expand Up @@ -55,10 +56,10 @@ default List<SyThemeClassNameType> themeClassesDefaultForComponent()
}

/**
* @return A read-only snapshot of the texts by Y offset
* @return A read-only snapshot of the positioned lines of text
*/

SortedMap<Integer, SyTextLineMeasuredType> textsByYOffset();
Iterable<SyTextLinePositioned> textLinesPositioned();

/**
* Determine the minimum size on the Y axis required to display the
Expand All @@ -70,4 +71,12 @@ default List<SyThemeClassNameType> themeClassesDefaultForComponent()
*/

int minimumSizeYRequired(SyLayoutContextType layoutContext);

/**
* @param y The Y offset
*
* @return The line starting at Y offset {@code y}
*/

Optional<SyTextLineMeasuredType> textByYOffset(int y);
}
Expand Up @@ -22,7 +22,7 @@
* text direction (left-to-right vs right-to-left, for example).
*/

public interface SySpaceTextType extends SySpaceType
public interface SySpaceTextAlignedType extends SySpaceType
{
// No value-level representation.
}
Expand Up @@ -64,43 +64,35 @@ public interface SyFontType
* Split the given text into lines based on the given page width; lines will
* be broken in order to ensure that text fits within the page width.
*
* @param textID The text identifier
* @param text The text
* @param firstLineNumber The number of the first line
* @param pageWidth The page width
* @param textID The text identifier
* @param text The text
* @param pageWidth The page width
*
* @return The non-empty list of split lines
*/

default List<SyTextLineMeasuredType> textLayout(
final SyTextID textID,
final SyText text,
final SyTextLineNumber firstLineNumber,
final int pageWidth)
{
final var m = new TreeMap<SyTextID, SyText>();
m.put(textID, text);
return this.textLayoutMultiple(
m,
firstLineNumber,
pageWidth
);
return this.textLayoutMultiple(m, pageWidth);
}

/**
* Split the given texts into lines based on the given page width; lines will
* be broken in order to ensure that text fits within the page width.
*
* @param texts The texts
* @param firstLineNumber The number of the first line
* @param pageWidth The page width
* @param texts The texts
* @param pageWidth The page width
*
* @return The split lines
*/

List<SyTextLineMeasuredType> textLayoutMultiple(
SortedMap<SyTextID, SyText> texts,
SyTextLineNumber firstLineNumber,
int pageWidth
);
}
Expand Up @@ -17,9 +17,8 @@

package com.io7m.jsycamore.api.text;

import com.io7m.jregions.core.parameterized.sizes.PAreaSizeI;
import com.io7m.jsycamore.api.spaces.SySpaceParentRelativeType;
import com.io7m.jsycamore.api.spaces.SySpaceTextType;
import com.io7m.jsycamore.api.spaces.SySpaceTextAlignedType;
import com.io7m.jtensors.core.parameterized.vectors.PVector2I;

/**
Expand All @@ -33,23 +32,22 @@
public interface SyTextLineMeasuredType
{
/**
* The bounds in terms of a line on a page: The bounds with a height equal
* to the text, and the width equal to the page width.
*
* @return The size of the page line
* @return The width of the page within this line resides
*/

PAreaSizeI<SySpaceParentRelativeType> pageLineBounds();
int pageWidth();

/**
* The smallest bounds that can contain the given text. An area of this
* size will be positioned somewhere within an area of size {@link #pageLineBounds()}
* for rendering and mouse interactions.
*
* @return The size of the text line
* @return The height required to contain this text
*/

int height();

/**
* @return The smallest width that can contain the given text.
*/

PAreaSizeI<SySpaceParentRelativeType> textBounds();
int textWidth();

/**
* @return The original text that produced this line
Expand All @@ -66,15 +64,18 @@ public interface SyTextLineMeasuredType
/**
* Inspect the text at the given position. The information returned includes
* details such as the index of the character within the string at the given
* location, information for rendering a caret, etc.
* location, information for rendering a caret, etc. The location will be
* reported to be at line {@code lineNumber}.
*
* @param position The position
* @param lineNumber The line number
* @param position The position
*
* @return Information about text at the given position
*/

SyTextLocationType inspectAt(
PVector2I<SySpaceTextType> position);
SyTextLineNumber lineNumber,
PVector2I<SySpaceTextAlignedType> position);

/**
* Transform the given parent-relative coordinates to text-space coordinates.
Expand All @@ -84,28 +85,26 @@ SyTextLocationType inspectAt(
* @return The equivalent text-space position
*/

PVector2I<SySpaceTextType> transformToTextCoordinates(
PVector2I<SySpaceTextAlignedType> transformToTextCoordinates(
PVector2I<SySpaceParentRelativeType> position);

/**
* Inspect the character at the given parent relative location.
* Inspect the character at the given parent relative location. The location
* will be reported to be at line {@code lineNumber}.
*
* @param position The parent-relative position
* @param lineNumber The line number
* @param position The parent-relative position
*
* @return The character at the given location
*/

default SyTextLocationType inspectAtParentRelative(
final SyTextLineNumber lineNumber,
final PVector2I<SySpaceParentRelativeType> position)
{
return this.inspectAt(
lineNumber,
this.transformToTextCoordinates(position)
);
}

/**
* @return The line number
*/

SyTextLineNumber lineNumber();
}
@@ -0,0 +1,48 @@
/*
* Copyright © 2023 Mark Raynsford <code@io7m.com> https://www.io7m.com
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/


package com.io7m.jsycamore.api.text;

import java.util.Objects;

/**
* A positioned text line produced from a text.
*
* @param y The y position
* @param textLineNumber The line number
* @param textLine The line
*/

public record SyTextLinePositioned(
int y,
SyTextLineNumber textLineNumber,
SyTextLineMeasuredType textLine)
{
/**
* A positioned text line produced from a text.
*
* @param y The y position
* @param textLineNumber The line number
* @param textLine The line
*/

public SyTextLinePositioned
{
Objects.requireNonNull(textLineNumber, "textLineNumber");
Objects.requireNonNull(textLine, "textLine");
}
}
Expand Up @@ -58,14 +58,6 @@ public interface SyTextMultiLineModelReadableType
Optional<SyText> textSectionContainingLine(
SyTextLineNumber lineNumber);

/**
* The set of measured lines with their associated Y coordinate.
*
* @return The measured lines
*/

SortedMap<Integer, SyTextLineMeasuredType> linesByYCoordinate();

/**
* Inspect the text at the given position. The information returned includes
* details such as the index of the character within the string at the given
Expand All @@ -88,4 +80,18 @@ Optional<SyTextLocationType> inspectAt(
*/

int minimumSizeYRequired();

/**
* @return A read-only snapshot of the positioned lines of text
*/

Iterable<SyTextLinePositioned> textLinesPositioned();

/**
* @param y The y offset
*
* @return The measured line that starts at Y offset {@code y}
*/

Optional<SyTextLineMeasuredType> textByYOffset(int y);
}
Expand Up @@ -17,13 +17,11 @@

package com.io7m.jsycamore.awt.internal;

import com.io7m.jregions.core.parameterized.sizes.PAreaSizeI;
import com.io7m.jsycamore.api.text.SyFontDescription;
import com.io7m.jsycamore.api.text.SyFontType;
import com.io7m.jsycamore.api.text.SyText;
import com.io7m.jsycamore.api.text.SyTextID;
import com.io7m.jsycamore.api.text.SyTextLineMeasuredType;
import com.io7m.jsycamore.api.text.SyTextLineNumber;

import java.awt.Font;
import java.awt.FontMetrics;
Expand Down Expand Up @@ -96,7 +94,6 @@ public SyFontDescription description()
@Override
public List<SyTextLineMeasuredType> textLayoutMultiple(
final SortedMap<SyTextID, SyText> texts,
final SyTextLineNumber firstLineNumber,
final int pageWidth)
{
Objects.requireNonNull(texts, "texts");
Expand All @@ -108,17 +105,14 @@ public List<SyTextLineMeasuredType> textLayoutMultiple(
final var results =
new LinkedList<SyTextLineMeasuredType>();

var lineNumber = firstLineNumber;

for (final var textEntry : texts.entrySet()) {
final var textID =
textEntry.getKey();
final var text =
textEntry.getValue();

if (text.value().isEmpty()) {
results.add(this.emptySectionLine(pageWidth, textID, lineNumber));
lineNumber = lineNumber.next();
results.add(this.emptySectionLine(pageWidth, textID));
continue;
}

Expand Down Expand Up @@ -162,16 +156,15 @@ public List<SyTextLineMeasuredType> textLayoutMultiple(
final var line =
new SyAWTTextAnalyzed(
pageWidth,
PAreaSizeI.of(textWidth, this.textHeight()),
lineNumber,
textWidth,
this.textHeight(),
layout,
textID,
new SyText(brokenText, text.direction())
);

results.add(line);
indexThen = indexNow;
lineNumber = lineNumber.next();
}
}

Expand All @@ -180,13 +173,12 @@ public List<SyTextLineMeasuredType> textLayoutMultiple(

private SyTextLineMeasuredType emptySectionLine(
final int pageWidth,
final SyTextID textID,
final SyTextLineNumber lineNumber)
final SyTextID textID)
{
return new SyAWTTextAnalyzed(
pageWidth,
PAreaSizeI.of(0, this.textHeight()),
lineNumber,
0,
this.textHeight(),
new TextLayout(" ", this.font, this.metrics.getFontRenderContext()),
textID,
SyText.empty()
Expand Down

0 comments on commit 11e89ca

Please sign in to comment.