internal LsErr GetPrevHyphenOpp( IntPtr pols, // Line Layout context int lscpStartSearch, // LSCP to start search for hyphen opportunity int lsdcpSearch, // number of LSCP to look for the hyphen opportunity ref int fHyphenFound, // [out] hyphen found ref int lscpHyphen, // [out] LSCP of character before hyphen ref LsHyph lsHyph // [out] hyphen info ) { LsErr lserr = LsErr.None; try { fHyphenFound = FullText.FindNextHyphenBreak( lscpStartSearch + 1, -lsdcpSearch, false, // !isCurrentAtWordStart ref lscpHyphen, ref lsHyph ) ? 1 : 0; Invariant.Assert(fHyphenFound == 0 || (lscpHyphen > lscpStartSearch - lsdcpSearch && lscpHyphen <= lscpStartSearch)); } catch (Exception e) { SaveException(e, Plsrun.Undefined, null); lserr = LsErr.ClientAbort; } catch { SaveNonCLSException("GetPrevHyphenOpp", Plsrun.Undefined, null); lserr = LsErr.ClientAbort; } return lserr; }
/// <summary> /// Find the hyphen break following or preceding the specified current LSCP /// </summary> /// <remarks> /// This method never checks whether the specified current LSCP is already right /// at a hyphen break. It either finds the next or the previous break regardless. /// /// A negative lscchLim param value indicates the caller finds the hyphen immediately /// before the specified character index. /// </remarks> /// <param name="lscpCurrent">the current LSCP</param> /// <param name="lscchLim">the number of LSCP to search for break</param> /// <param name="isCurrentAtWordStart">flag indicates whether lscpCurrent is the beginning of the word to hyphenate</param> /// <param name="lscpHyphen">LSCP of the hyphen</param> /// <param name="lshyph">Hyphen properties</param> internal bool FindNextHyphenBreak( int lscpCurrent, int lscchLim, bool isCurrentAtWordStart, ref int lscpHyphen, ref LsHyph lshyph ) { lshyph = new LsHyph(); // no additional hyphen properties for now if (_store.Pap.Hyphenator != null) { int lscpChunk; int lscchChunk; LexicalChunk chunk = GetChunk( _store.Pap.Hyphenator, lscpCurrent, lscchLim, isCurrentAtWordStart, out lscpChunk, out lscchChunk ); _lscpHyphenationLookAhead = lscpChunk + lscchChunk; if (!chunk.IsNoBreak) { int ichCurrent = chunk.LSCPToCharacterIndex(lscpCurrent - lscpChunk); int ichLim = chunk.LSCPToCharacterIndex(lscpCurrent + lscchLim - lscpChunk); if (lscchLim >= 0) { int ichNext = chunk.Breaks.GetNextBreak(ichCurrent); if (ichNext >= 0 && ichNext > ichCurrent && ichNext <= ichLim) { // -1 because ichNext is the character index where break occurs in front of it, // while LSCP is the position where break occurs after it. lscpHyphen = chunk.CharacterIndexToLSCP(ichNext - 1) + lscpChunk; return true; } } else { int ichPrev = chunk.Breaks.GetPreviousBreak(ichCurrent); if (ichPrev >= 0 && ichPrev <= ichCurrent && ichPrev > ichLim) { // -1 because ichPrev is the character index where break occurs in front of it, // while LSCP is the position where break occurs after it. lscpHyphen = chunk.CharacterIndexToLSCP(ichPrev - 1) + lscpChunk; return true; } } } } return false; }
internal LsErr Hyphenate( IntPtr pols, // Line Layout context int fLastHyphenFound, // whether last hyphen found? int lscpLastHyphen, // cp of the last found hyphen ref LsHyph lastHyph, // [in] last found hyphenation int lscpWordStart, // first character of word int lscpExceed, // first character in this word that exceeds column ref int fHyphenFound, // [out] hyphenation opportunity found? ref int lscpHyphen, // [out] cp of the character before hyphen ref LsHyph lsHyph // [out] hyphen info ) { LsErr lserr = LsErr.None; try { fHyphenFound = FullText.FindNextHyphenBreak( lscpWordStart, lscpExceed - lscpWordStart, true, // isCurrentAtWordStart ref lscpHyphen, ref lsHyph ) ? 1 : 0; Invariant.Assert(fHyphenFound == 0 || (lscpHyphen >= lscpWordStart && lscpHyphen < lscpExceed)); } catch (Exception e) { SaveException(e, Plsrun.Undefined, null); lserr = LsErr.ClientAbort; } catch { SaveNonCLSException("Hyphenate", Plsrun.Undefined, null); lserr = LsErr.ClientAbort; } return lserr; }