|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381 |
- /**************************************************************************\
- *
- * Copyright (c) 1998-2000, Microsoft Corp. All Rights Reserved.
- *
- * Module Name:
- *
- * GdiplusStringFormat.h
- *
- * Abstract:
- *
- * String format specification for DrawString and text APIs
- *
- \**************************************************************************/
-
- #ifndef _GDIPLUSSTRINGFORMAT_H
- #define _GDIPLUSSTRINGFORMAT_H
-
-
- class StringFormat : public GdiplusBase
- {
- public:
- friend class Graphics;
- friend class GraphicsPath;
-
-
- StringFormat(
- IN INT formatFlags = 0,
- IN LANGID language = LANG_NEUTRAL
- )
- {
- nativeFormat = NULL;
- lastError = DllExports::GdipCreateStringFormat(
- formatFlags,
- language,
- &nativeFormat
- );
- }
-
- static const StringFormat *GenericDefault();
- static const StringFormat *GenericTypographic();
-
- // Constructor based on existing string format
-
- StringFormat(
- IN const StringFormat *format
- )
- {
- nativeFormat = NULL;
- lastError = DllExports::GdipCloneStringFormat(
- format ? format->nativeFormat : NULL,
- &nativeFormat
- );
- }
-
- StringFormat *Clone() const
- {
- GpStringFormat *clonedStringFormat = NULL;
-
- lastError = DllExports::GdipCloneStringFormat(
- nativeFormat,
- &clonedStringFormat
- );
-
- if (lastError == Ok)
- return new StringFormat(clonedStringFormat, lastError);
- else
- return NULL;
- }
-
- ~StringFormat()
- {
- DllExports::GdipDeleteStringFormat(nativeFormat);
- }
-
- Status SetFormatFlags(IN INT flags)
- {
- return SetStatus(DllExports::GdipSetStringFormatFlags(
- nativeFormat,
- flags
- ));
- }
-
- INT GetFormatFlags() const
- {
- INT flags;
- SetStatus(DllExports::GdipGetStringFormatFlags(nativeFormat, &flags));
- return flags;
- }
-
- #ifndef DCR_USE_NEW_152154
- Status SetLineSpacing(
- IN REAL amount = 1.0f,
- IN LineSpacing method = LineSpacingRecommended
- )
- {
- return SetStatus(DllExports::GdipSetStringFormatLineSpacing(
- nativeFormat,
- amount,
- method
- ));
- }
- #endif
-
- Status SetAlignment(IN StringAlignment align)
- {
- return SetStatus(DllExports::GdipSetStringFormatAlign(
- nativeFormat,
- align
- ));
- }
-
- StringAlignment GetAlignment() const
- {
- StringAlignment alignment;
- SetStatus(DllExports::GdipGetStringFormatAlign(
- nativeFormat,
- &alignment
- ));
- return alignment;
- }
-
- Status SetLineAlignment(IN StringAlignment align)
- {
- return SetStatus(DllExports::GdipSetStringFormatLineAlign(
- nativeFormat,
- align
- ));
- }
-
- StringAlignment GetLineAlignment() const
- {
- StringAlignment alignment;
- SetStatus(DllExports::GdipGetStringFormatLineAlign(
- nativeFormat,
- &alignment
- ));
- return alignment;
- }
-
- Status SetHotkeyPrefix(IN HotkeyPrefix hotkeyPrefix)
- {
- return SetStatus(DllExports::GdipSetStringFormatHotkeyPrefix(
- nativeFormat,
- (INT)hotkeyPrefix
- ));
- }
-
- HotkeyPrefix GetHotkeyPrefix() const
- {
- HotkeyPrefix hotkeyPrefix;
- SetStatus(DllExports::GdipGetStringFormatHotkeyPrefix(
- nativeFormat,
- (INT*)&hotkeyPrefix
- ));
- return hotkeyPrefix;
- }
-
- Status SetTabStops(
- IN REAL firstTabOffset,
- IN INT count,
- IN const REAL *tabStops
- )
- {
- return SetStatus(DllExports::GdipSetStringFormatTabStops(
- nativeFormat,
- firstTabOffset,
- count,
- tabStops
- ));
- }
-
- INT GetTabStopCount() const
- {
- INT count;
- SetStatus(DllExports::GdipGetStringFormatTabStopCount(nativeFormat, &count));
- return count;
- }
-
- Status GetTabStops(
- IN INT count,
- OUT REAL *firstTabOffset,
- OUT REAL *tabStops
- ) const
- {
- return SetStatus(DllExports::GdipGetStringFormatTabStops(
- nativeFormat,
- count,
- firstTabOffset,
- tabStops
- ));
- }
-
- #ifdef DCR_USE_NEW_146933
- Status SetDigitSubstitution(
- IN LANGID language,
- IN StringDigitSubstitute substitute
- )
- {
- return SetStatus(DllExports::GdipSetStringFormatDigitSubstitution(
- nativeFormat,
- language,
- substitute
- ));
- }
-
- LANGID GetDigitSubstitutionLanguage(
- ) const
- {
- LANGID language;
- SetStatus(DllExports::GdipGetStringFormatDigitSubstitution(
- nativeFormat,
- &language,
- NULL
- ));
- return language;
- }
-
- StringDigitSubstitute GetDigitSubstitutionMethod(
- ) const
- {
- StringDigitSubstitute substitute;
- SetStatus(DllExports::GdipGetStringFormatDigitSubstitution(
- nativeFormat,
- NULL,
- &substitute
- ));
- return substitute;
- }
- #endif // DCR_USE_NEW_146933
-
- // String trimming. How to handle more text than can be displayed
- // in the limits available.
-
- Status SetTrimming(IN StringTrimming trimming)
- {
- return SetStatus(DllExports::GdipSetStringFormatTrimming(
- nativeFormat,
- trimming
- ));
- }
-
- StringTrimming GetTrimming() const
- {
- StringTrimming trimming;
- SetStatus(DllExports::GdipGetStringFormatTrimming(
- nativeFormat,
- &trimming
- ));
- return trimming;
- }
-
- #ifdef DCR_USE_NEW_174340
- Status SetMeasurableCharacterRanges(
- IN INT rangeCount,
- IN const CharacterRange *ranges
- )
- {
- return SetStatus(DllExports::GdipSetStringFormatMeasurableCharacterRanges(
- nativeFormat,
- rangeCount,
- ranges
- ));
- }
-
- INT GetMeasurableCharacterRangeCount()
- {
- INT count;
- SetStatus(DllExports::GdipGetStringFormatMeasurableCharacterRangeCount(
- nativeFormat,
- &count
- ));
- return count;
- }
- #endif
-
- // GetLastStatus - return last error code and clear error code
-
- Status GetLastStatus() const
- {
- Status lastStatus = lastError;
- lastError = Ok;
-
- return lastStatus;
- }
-
- protected:
-
- Status SetStatus(GpStatus newStatus) const
- {
- if (newStatus == Ok)
- {
- return Ok;
- }
- else
- {
- return lastError = newStatus;
- }
- }
-
-
- // Not allowed and move to private
- StringFormat(const StringFormat &source)
- {
- nativeFormat = NULL;
- lastError = DllExports::GdipCloneStringFormat(
- source.nativeFormat,
- &nativeFormat
- );
- }
-
- StringFormat& operator=(const StringFormat &source)
- {
- DllExports::GdipDeleteStringFormat(nativeFormat);
- lastError = DllExports::GdipCloneStringFormat(
- source.nativeFormat,
- &nativeFormat
- );
- return *this;
- }
-
-
- // private constructor for copy
- StringFormat(GpStringFormat * clonedStringFormat, Status status)
- {
- lastError = status;
- nativeFormat = clonedStringFormat;
-
- }
-
- GpStringFormat *nativeFormat;
- mutable Status lastError;
- };
-
- // Generic constant string formats.
-
- static BYTE GenericTypographicStringFormatBuffer[sizeof(StringFormat)] = {0};
- static BYTE GenericDefaultStringFormatBuffer[sizeof(StringFormat)] = {0};
-
- static StringFormat *GenericTypographicStringFormat = NULL;
- static StringFormat *GenericDefaultStringFormat = NULL;
-
- // Define the generic string formats
-
-
- inline const StringFormat *StringFormat::GenericDefault()
- {
- if (GenericDefaultStringFormat != NULL)
- {
- return GenericDefaultStringFormat;
- }
-
- GenericDefaultStringFormat =
- (StringFormat*)GenericDefaultStringFormatBuffer;
-
- GenericDefaultStringFormat->lastError =
- DllExports::GdipStringFormatGetGenericDefault(
- &(GenericDefaultStringFormat->nativeFormat)
- );
-
- return GenericDefaultStringFormat;
- }
-
- inline const StringFormat *StringFormat::GenericTypographic()
- {
- if (GenericTypographicStringFormat != NULL)
- {
- return GenericTypographicStringFormat;
- }
-
- GenericTypographicStringFormat =
- (StringFormat*)GenericTypographicStringFormatBuffer;
-
- GenericTypographicStringFormat->lastError =
- DllExports::GdipStringFormatGetGenericTypographic(
- &GenericTypographicStringFormat->nativeFormat
- );
-
- return GenericTypographicStringFormat;
- }
-
- #endif // !_GDIPLUSSTRINGFORMAT_H
|