1998-10-20 04:17:17 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS"
|
|
|
|
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
|
|
|
* the License for the specific language governing rights and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
|
|
|
* Netscape Communications Corporation. All Rights Reserved.
|
|
|
|
*/
|
|
|
|
#ifndef nsTextTransformer_h___
|
|
|
|
#define nsTextTransformer_h___
|
|
|
|
|
|
|
|
#include "nsTextFragment.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
|
1999-09-17 03:31:59 +04:00
|
|
|
class nsIContent;
|
1998-10-20 04:17:17 +04:00
|
|
|
class nsIFrame;
|
|
|
|
class nsTextRun;
|
1999-02-24 21:21:23 +03:00
|
|
|
class nsILineBreaker;
|
1999-04-07 02:41:44 +04:00
|
|
|
class nsIWordBreaker;
|
1998-10-20 04:17:17 +04:00
|
|
|
|
1999-09-22 04:40:16 +04:00
|
|
|
#define NS_TEXT_TRANSFORMER_AUTO_WORD_BUF_SIZE 100
|
|
|
|
|
1998-10-20 04:17:17 +04:00
|
|
|
/**
|
|
|
|
* This object manages the transformation of text:
|
|
|
|
*
|
|
|
|
* <UL>
|
|
|
|
* <LI>whitespace compression
|
|
|
|
* <LI>capitalization
|
|
|
|
* <LI>lowercasing
|
|
|
|
* <LI>uppercasing
|
|
|
|
* </UL>
|
|
|
|
*
|
|
|
|
* Note that no transformations are applied that would impact word
|
|
|
|
* breaking (like mapping into space, for example). In
|
|
|
|
* addition, this logic will not strip leading or trailing whitespace
|
|
|
|
* (across the entire run of text; leading whitespace can be skipped
|
|
|
|
* for a frames text because of whitespace compression).
|
|
|
|
*/
|
|
|
|
class nsTextTransformer {
|
|
|
|
public:
|
1999-09-22 04:40:16 +04:00
|
|
|
// Note: The text transformer does not hold a reference to the line
|
|
|
|
// breaker and work breaker objects
|
|
|
|
nsTextTransformer(nsILineBreaker* aLineBreaker,
|
|
|
|
nsIWordBreaker *aWordBreaker);
|
1999-02-24 21:21:23 +03:00
|
|
|
|
1998-10-20 04:17:17 +04:00
|
|
|
~nsTextTransformer();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the text transform. This is when the transformation
|
|
|
|
* occurs. Subsequent calls to GetTransformedTextFor will just
|
|
|
|
* return the result of the single transformation.
|
|
|
|
*/
|
1999-09-17 03:31:59 +04:00
|
|
|
nsresult Init(nsIFrame* aFrame,
|
|
|
|
nsIContent* aContent,
|
1998-10-20 04:17:17 +04:00
|
|
|
PRInt32 aStartingOffset);
|
|
|
|
|
|
|
|
PRInt32 GetContentLength() const {
|
|
|
|
return mContentLength;
|
|
|
|
}
|
|
|
|
|
1998-10-20 20:45:14 +04:00
|
|
|
PRUnichar* GetNextWord(PRBool aInWord,
|
|
|
|
PRInt32& aWordLenResult,
|
1998-10-20 04:17:17 +04:00
|
|
|
PRInt32& aContentLenResult,
|
1999-04-07 02:41:44 +04:00
|
|
|
PRBool& aIsWhitespaceResult,
|
|
|
|
PRBool aForLineBreak = PR_TRUE);
|
1998-10-20 04:17:17 +04:00
|
|
|
|
1999-02-22 06:20:59 +03:00
|
|
|
PRUnichar* GetPrevWord(PRBool aInWord,
|
|
|
|
PRInt32& aWordLenResult,
|
|
|
|
PRInt32& aContentLenResult,
|
1999-04-07 02:41:44 +04:00
|
|
|
PRBool& aIsWhitespaceResult,
|
|
|
|
PRBool aForLineBreak = PR_TRUE);
|
1998-10-20 04:17:17 +04:00
|
|
|
PRBool HasMultibyte() const {
|
|
|
|
return mHasMultibyte;
|
|
|
|
}
|
|
|
|
|
1999-09-22 04:40:16 +04:00
|
|
|
PRUnichar* GetWordBuffer() {
|
|
|
|
return mBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 GetWordBufferLength() const {
|
|
|
|
return mBufferLength;
|
|
|
|
}
|
1998-10-20 04:17:17 +04:00
|
|
|
|
|
|
|
protected:
|
1999-09-22 04:40:16 +04:00
|
|
|
PRBool GrowBuffer(PRBool aForNextWord = PR_TRUE);
|
1998-10-20 20:45:14 +04:00
|
|
|
|
1998-10-20 04:17:17 +04:00
|
|
|
PRUnichar* mBuffer;
|
|
|
|
PRInt32 mBufferLength;
|
|
|
|
PRBool mHasMultibyte;
|
|
|
|
|
|
|
|
PRInt32 mContentLength;
|
|
|
|
PRInt32 mStartingOffset;
|
|
|
|
PRInt32 mOffset;
|
|
|
|
|
1999-10-16 03:36:07 +04:00
|
|
|
const nsTextFragment* mFrag;
|
1998-10-20 04:17:17 +04:00
|
|
|
PRInt32 mCurrentFragOffset;
|
|
|
|
|
1998-10-20 20:45:14 +04:00
|
|
|
PRUint8 mTextTransform;
|
1999-03-31 08:12:46 +04:00
|
|
|
PRUint8 mPreformatted;
|
1999-02-24 21:21:23 +03:00
|
|
|
|
1999-09-17 03:31:59 +04:00
|
|
|
nsILineBreaker* mLineBreaker; // does NOT hold reference
|
|
|
|
nsIWordBreaker* mWordBreaker; // does NOT hold reference
|
1999-09-22 04:40:16 +04:00
|
|
|
|
|
|
|
PRUnichar mAutoWordBuffer[NS_TEXT_TRANSFORMER_AUTO_WORD_BUF_SIZE];
|
1998-10-20 04:17:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsTextTransformer_h___ */
|