@@ -5,10 +5,8 @@ import insertGlyph from '../../attributedString/insertGlyph';
55import advanceWidthBetween from '../../attributedString/advanceWidthBetween' ;
66import { AttributedString , Attributes , LayoutOptions } from '../../types' ;
77import { Node } from './types' ;
8- import generateGlyphs from '../../layout/generateGlyphs' ;
98
10- const SOFT_HYPHEN = '\u00AD' ;
11- const HYPHEN_CODE_POINT = 0x002d ;
9+ const HYPHEN = 0x002d ;
1210const TOLERANCE_STEPS = 5 ;
1311const TOLERANCE_LIMIT = 50 ;
1412
@@ -47,49 +45,23 @@ const breakLines = (
4745 end = prevNode . end ;
4846
4947 line = slice ( start , end , attributedString ) ;
50- if ( node . width > 0 ) {
51- // A non-zero-width penalty indicates an additional hyphen should be inserted
52- line = insertGlyph ( line . string . length , HYPHEN_CODE_POINT , line ) ;
53- }
48+
49+ line = insertGlyph ( line . string . length , HYPHEN , line ) ;
5450 } else {
5551 end = node . end ;
5652 line = slice ( start , end , attributedString ) ;
5753 }
5854
5955 start = end ;
6056
61- return [ ...acc , removeSoftHyphens ( line ) ] ;
57+ return [ ...acc , line ] ;
6258 } , [ ] ) ;
6359
64- const lastLine = slice (
65- start ,
66- attributedString . string . length ,
67- attributedString ,
68- ) ;
69- lines . push ( removeSoftHyphens ( lastLine ) ) ;
60+ lines . push ( slice ( start , attributedString . string . length , attributedString ) ) ;
7061
7162 return lines ;
7263} ;
7364
74- /**
75- * Remove all soft hyphen characters from the line.
76- * Soft hyphens are not relevant anymore after line breaking, and will only
77- * disrupt the rendering later down the line if left in the text.
78- *
79- * @param line
80- */
81- const removeSoftHyphens = ( line : AttributedString ) : AttributedString => {
82- const modifiedLine = {
83- ...line ,
84- string : line . string . split ( SOFT_HYPHEN ) . join ( '' ) ,
85- } ;
86-
87- return {
88- ...modifiedLine ,
89- ...generateGlyphs ( ) ( modifiedLine ) ,
90- } ;
91- } ;
92-
9365/**
9466 * Return Knuth & Plass nodes based on line and previously calculated syllables
9567 *
@@ -106,7 +78,6 @@ const getNodes = (
10678 let start = 0 ;
10779
10880 const hyphenWidth = 5 ;
109- const softHyphen = '\u00ad' ;
11081
11182 const { syllables } = attributedString ;
11283
@@ -136,8 +107,7 @@ const getNodes = (
136107
137108 if ( syllables [ index + 1 ] && hyphenated ) {
138109 // Add penalty node. Penalty nodes are used to represent hyphenation points.
139- const penaltyWidth = s . endsWith ( softHyphen ) ? hyphenWidth : 0 ;
140- acc . push ( knuthPlass . penalty ( penaltyWidth , hyphenPenalty , 1 ) ) ;
110+ acc . push ( knuthPlass . penalty ( hyphenWidth , hyphenPenalty , 1 ) ) ;
141111 }
142112 }
143113
0 commit comments