eudora-mac/unicode.c

1 line
59 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. */ #define MAX_UTF8_CHAR_LEN (((sizeof(UniChar) * 8) / 6) + ((6 - ((sizeof(UniChar) * 8) / 6)) < ((sizeof(UniChar) * 8) % 6) ? 2 : 1)) #if __profile__ #include "unicodeprofile.h" #endif typedef enum { umFlowedDir, umCharsetDir, umHtmlDir, umRichDir, umDirCount } umDirectives; typedef enum { umHeaderState, umFlowedState, umCharsetState, umHtmlState, umRichState, umTextState, } umStates; typedef struct { Byte xState; Byte tState; Byte cState; Byte oState; } UniGlobalsState; static struct UniGlobals { TECObjectRef internetToUTF8; TextEncoding internetToUTF8Encoding; Boolean maclatin1; UnicodeToTextRunInfo UTF8ToMac; IntlConverter quickConverter; ByteCount origTextLen; TextPtr *origText; ByteCount convTextLen; TextPtr *convText; ItemCount convRunsCount; TextEncodingRun **convRuns; FormatOrderPtr *order; UInt16 tecVersion; Boolean hasTextRunFlag; Boolean has88591VariantsFlag; } uGlobals = {0}; OSStatus ConvertUTF8Text(BytePtr theText, ByteCount bufLen); OSStatus DrawConvertedUTF8(short width, ScriptFontInfo fonts); OSStatus MeasureConvertedUTF8(short *width, FontInfo *maxFont, Boolean *rightToLeft, ScriptFontInfo fonts); pascal long MyVisibleLength(Ptr textPtr, long len, short direction); pascal Boolean MyRlDirProc(short theFormat, void *dirParam); long EnsureHandleSize(Handle h, Size s); void NoPurgeUniGlobals(UniGlobalsState *uniState); void ResetUniGlobals(UniGlobalsState *uniState); OSStatus GetUnicodeHint(TextEncoding encoding, StringPtr lang, UniChar *hint); OSStatus ClearIntlConverterContext(UnicodeToTextRunInfo converter, Boolean utf8); OSStatus UpdateIntlConverterLo(IntlConverter *converter, StringPtr charset, TextEncoding encoding); OSStatus UpdateTECConverter(TECObjectRef *converter, StringPtr charset, TextEncoding newEncoding, TextEncoding *fromEncoding, TextEncoding toEncoding, Boolean *maclatin1, UniChar *hint); UniCharCount UTF8CharCount(BytePtr utf8, ByteCount bufLen); OSErr AccuEnsureSize(AccuPtr a, long len, long incr); short GetIntlFont(ScriptCode script, ScriptFontInfo fonts); short GetIntlSize(ScriptCode script, ScriptFontInfo fonts); void CleanISO2022(TextPtr text, long len, IntlConverter *converter); OSStatus InsertIntlHeaders(Handle text, long len, long tOff, AccuPtr a, TextEncoding encoding, PETEHandle pte, long *pOff); long ParseCharset(Ptr textPtr, long len, PStr charset, umDirectives c); OSErr PeteGetStyleRun(PETEHandle pte, long offs