eudora-mac/Editor/Source/Editor Source/reflow.c

1 line
28 KiB
C
Raw Normal View History

2018-05-23 09:59:15 +00:00
/* Copyright (c) 2017, Computer History Museum All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted (subject to the limitations in the disclaimer below) provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Computer History Museum nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "petepch.h" #define USEOWNSTYLEDLINEBREAK 1 OSErr CheckParagraphMeasure(DocumentInfoHandle docInfo, long paraNum, Boolean needLineStarts) { if(paraNum > (**docInfo).paraCount) { return invalidIndexErr; } if((**docInfo).paraArray[paraNum].paraLSDirty || (needLineStarts && *((**(**docInfo).paraArray[paraNum].paraInfo).lineStarts) == nil)) { return ReflowParagraph(docInfo, paraNum, 0L, LONG_MAX); } else { return noErr; } } Boolean FindAndCompressLineStarts(LSTable lineStarts, LSPtr curLine, long lineIndex, long* lineCount) { long startLineIndex; for(startLineIndex = lineIndex; (lineIndex < *lineCount) && (curLine->lsStartChar >= (*lineStarts)[lineIndex].lsStartChar); ++lineIndex) { if((curLine->lsStartChar == (*lineStarts)[lineIndex].lsStartChar) && (curLine->lsScriptRunLen == (*lineStarts)[lineIndex].lsScriptRunLen)) { Munger((Handle)lineStarts, startLineIndex * sizeof(LSElement), nil, (lineIndex - startLineIndex) * sizeof(LSElement), nil, 0L); if(MemError() == noErr) { *lineCount -= lineIndex - startLineIndex; return true; } else { break; } } } return false; } /* Recalculate the line starts for a paragraph between two offsets */ OSErr ReflowParagraph(DocumentInfoHandle docInfo, long paraNum, long startChar, long endChar) { long lineCount, lineIndex, tempOffset; LSElement tempLine; LSTable lineStarts; Byte hState; OSErr errCode; if((**docInfo).flags.recalcOff || (**docInfo).flags.progressLoopCalled) { return cantDoThatInCurrentMode; } /* Get the lineStarts handle */ lineStarts = (**(**docInfo).paraArray[paraNum].paraInfo).lineStarts; /* If the lineStarts handle has been purged, reallocate it */ if(*lineStarts == nil) { ReallocateHandle((Handle)lineStarts, 0L); if((errCode = MemError()) != noErr) { (**docInfo).flags.docCorrupt = true; return errCode; } HPurge((Handle)lineStarts); } errCode = noErr; /* Make the lineStarts handle non-purgable */ hState = HGetState((Handle)lineStarts); HNoPurge((Handle)lineStarts); /* Determine how many lines are now in the lineStarts handle */ lineCount = InlineGetHandleSize((Handle)lineStarts) / sizeof(LSElement) - 1L; /* Subtract the paragraph height from the document height */ (**docInfo).docHeight -= (**docInfo).paraArray[paraNum].paraHeight; (**docInfo).paraArray[paraNum].paraHeight = 0L; for(lineIndex = 0L; lineIndex < lineCount - 1L;