GdiPlusStringFormat.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:8k
源码类别:

模拟服务器

开发平台:

C/C++

  1. /**************************************************************************
  2. *
  3. * Copyright (c) 1998-2001, Microsoft Corp.  All Rights Reserved.
  4. *
  5. * Module Name:
  6. *
  7. *   GdiplusStringFormat.h
  8. *
  9. * Abstract:
  10. *
  11. *   GDI+ StringFormat class
  12. *
  13. **************************************************************************/
  14. #ifndef _GDIPLUSSTRINGFORMAT_H
  15. #define _GDIPLUSSTRINGFORMAT_H
  16. class StringFormat : public GdiplusBase
  17. {
  18. public:
  19.     friend class Graphics;
  20.     friend class GraphicsPath;
  21.     StringFormat(
  22.         IN INT     formatFlags = 0,
  23.         IN LANGID  language = LANG_NEUTRAL
  24.     )
  25.     {
  26.         nativeFormat = NULL;
  27.         lastError = DllExports::GdipCreateStringFormat(
  28.             formatFlags,
  29.             language,
  30.             &nativeFormat
  31.         );
  32.     }
  33.     static const StringFormat *GenericDefault();
  34.     static const StringFormat *GenericTypographic();
  35.     StringFormat(
  36.         IN const StringFormat *format
  37.     )
  38.     {
  39.         nativeFormat = NULL;
  40.         lastError = DllExports::GdipCloneStringFormat(
  41.             format ? format->nativeFormat : NULL,
  42.             &nativeFormat
  43.         );
  44.     }
  45.     StringFormat *Clone() const
  46.     {
  47.         GpStringFormat *clonedStringFormat = NULL;
  48.         lastError = DllExports::GdipCloneStringFormat(
  49.             nativeFormat,
  50.             &clonedStringFormat
  51.         );
  52.         if (lastError == Ok)
  53.             return new StringFormat(clonedStringFormat, lastError);
  54.         else
  55.             return NULL;
  56.     }
  57.     ~StringFormat()
  58.     {
  59.         DllExports::GdipDeleteStringFormat(nativeFormat);
  60.     }
  61.     Status SetFormatFlags(IN INT flags)
  62.     {
  63.         return SetStatus(DllExports::GdipSetStringFormatFlags(
  64.             nativeFormat,
  65.             flags
  66.         ));
  67.     }
  68.     INT GetFormatFlags() const
  69.     {
  70.         INT flags;
  71.         SetStatus(DllExports::GdipGetStringFormatFlags(nativeFormat, &flags));
  72.         return flags;
  73.     }
  74.     Status SetAlignment(IN StringAlignment align)
  75.     {
  76.         return SetStatus(DllExports::GdipSetStringFormatAlign(
  77.             nativeFormat,
  78.             align
  79.         ));
  80.     }
  81.     StringAlignment GetAlignment() const
  82.     {
  83.         StringAlignment alignment;
  84.         SetStatus(DllExports::GdipGetStringFormatAlign(
  85.             nativeFormat,
  86.             &alignment
  87.         ));
  88.         return alignment;
  89.     }
  90.     Status SetLineAlignment(IN StringAlignment align)
  91.     {
  92.         return SetStatus(DllExports::GdipSetStringFormatLineAlign(
  93.             nativeFormat,
  94.             align
  95.         ));
  96.     }
  97.     StringAlignment GetLineAlignment() const
  98.     {
  99.         StringAlignment alignment;
  100.         SetStatus(DllExports::GdipGetStringFormatLineAlign(
  101.             nativeFormat,
  102.             &alignment
  103.         ));
  104.         return alignment;
  105.     }
  106.     Status SetHotkeyPrefix(IN HotkeyPrefix hotkeyPrefix)
  107.     {
  108.         return SetStatus(DllExports::GdipSetStringFormatHotkeyPrefix(
  109.             nativeFormat,
  110.             (INT)hotkeyPrefix
  111.         ));
  112.     }
  113.     HotkeyPrefix GetHotkeyPrefix() const
  114.     {
  115.         HotkeyPrefix hotkeyPrefix;
  116.         SetStatus(DllExports::GdipGetStringFormatHotkeyPrefix(
  117.             nativeFormat,
  118.             (INT*)&hotkeyPrefix
  119.         ));
  120.         return hotkeyPrefix;
  121.     }
  122.     Status SetTabStops(
  123.         IN REAL    firstTabOffset,
  124.         IN INT     count,
  125.         IN const REAL    *tabStops
  126.     )
  127.     {
  128.         return SetStatus(DllExports::GdipSetStringFormatTabStops(
  129.             nativeFormat,
  130.             firstTabOffset,
  131.             count,
  132.             tabStops
  133.         ));
  134.     }
  135.     INT GetTabStopCount() const
  136.     {
  137.         INT count;
  138.         SetStatus(DllExports::GdipGetStringFormatTabStopCount(nativeFormat, &count));
  139.         return count;
  140.     }
  141.     Status GetTabStops(
  142.         IN INT     count,
  143.         OUT REAL   *firstTabOffset,
  144.         OUT REAL   *tabStops
  145.     ) const
  146.     {
  147.         return SetStatus(DllExports::GdipGetStringFormatTabStops(
  148.             nativeFormat,
  149.             count,
  150.             firstTabOffset,
  151.             tabStops
  152.         ));
  153.     }
  154.     Status SetDigitSubstitution(
  155.         IN LANGID                language,
  156.         IN StringDigitSubstitute substitute
  157.     )
  158.     {
  159.         return SetStatus(DllExports::GdipSetStringFormatDigitSubstitution(
  160.             nativeFormat,
  161.             language,
  162.             substitute
  163.         ));
  164.     }
  165.     LANGID GetDigitSubstitutionLanguage(
  166.     ) const
  167.     {
  168.         LANGID language;
  169.         SetStatus(DllExports::GdipGetStringFormatDigitSubstitution(
  170.             nativeFormat,
  171.             &language,
  172.             NULL
  173.         ));
  174.         return language;
  175.     }
  176.     StringDigitSubstitute GetDigitSubstitutionMethod(
  177.     ) const
  178.     {
  179.         StringDigitSubstitute substitute;
  180.         SetStatus(DllExports::GdipGetStringFormatDigitSubstitution(
  181.             nativeFormat,
  182.             NULL,
  183.             &substitute
  184.         ));
  185.         return substitute;
  186.     }
  187.     Status SetTrimming(IN StringTrimming trimming)
  188.     {
  189.         return SetStatus(DllExports::GdipSetStringFormatTrimming(
  190.             nativeFormat,
  191.             trimming
  192.         ));
  193.     }
  194.     StringTrimming StringFormat::GetTrimming() const
  195.     {
  196.         StringTrimming trimming;
  197.         SetStatus(DllExports::GdipGetStringFormatTrimming(
  198.             nativeFormat,
  199.             &trimming
  200.         ));
  201.         return trimming;
  202.     }
  203.     Status SetMeasurableCharacterRanges(
  204.         IN INT                  rangeCount,
  205.         IN const CharacterRange *ranges
  206.     )
  207.     {
  208.         return SetStatus(DllExports::GdipSetStringFormatMeasurableCharacterRanges(
  209.             nativeFormat,
  210.             rangeCount,
  211.             ranges
  212.         ));
  213.     }
  214.     INT GetMeasurableCharacterRangeCount()
  215.     {
  216.         INT count;
  217.         SetStatus(DllExports::GdipGetStringFormatMeasurableCharacterRangeCount(
  218.             nativeFormat,
  219.             &count
  220.         ));
  221.         return count;
  222.     }
  223.     Status GetLastStatus() const
  224.     {
  225.         Status lastStatus = lastError;
  226.         lastError = Ok;
  227.         return lastStatus;
  228.     }
  229. protected:
  230.     Status SetStatus(GpStatus newStatus) const
  231.     {
  232.         if (newStatus == Ok)
  233.         {
  234.             return Ok;
  235.         }
  236.         else
  237.         {
  238.             return lastError = newStatus;
  239.         }
  240.     }
  241.     StringFormat(const StringFormat &source)
  242.     {
  243.         nativeFormat = NULL;
  244.         lastError = DllExports::GdipCloneStringFormat(
  245.             source.nativeFormat,
  246.             &nativeFormat
  247.         );
  248.     }
  249.     StringFormat& operator=(const StringFormat &source)
  250.     {
  251.         DllExports::GdipDeleteStringFormat(nativeFormat);
  252.         lastError = DllExports::GdipCloneStringFormat(
  253.             source.nativeFormat,
  254.             &nativeFormat
  255.         );
  256.         return *this;
  257.     }
  258.     StringFormat(GpStringFormat * clonedStringFormat, Status status)
  259.     {
  260.         lastError = status;
  261.         nativeFormat = clonedStringFormat;
  262.     }
  263.     GpStringFormat *nativeFormat;
  264.     mutable Status  lastError;
  265. };
  266. static BYTE GenericTypographicStringFormatBuffer[sizeof(StringFormat)] = {0};
  267. static BYTE GenericDefaultStringFormatBuffer[sizeof(StringFormat)] = {0};
  268. inline const StringFormat *StringFormat::GenericDefault()
  269. {
  270.     StringFormat * genericDefaultStringFormat =
  271.         (StringFormat*)GenericDefaultStringFormatBuffer;
  272.     genericDefaultStringFormat->lastError =
  273.         DllExports::GdipStringFormatGetGenericDefault(
  274.             &(genericDefaultStringFormat->nativeFormat)
  275.         );
  276.     return genericDefaultStringFormat;
  277. }
  278. inline const StringFormat *StringFormat::GenericTypographic()
  279. {
  280.     StringFormat * genericTypographicStringFormat =
  281.         (StringFormat*)GenericTypographicStringFormatBuffer;
  282.     genericTypographicStringFormat->lastError =
  283.         DllExports::GdipStringFormatGetGenericTypographic(
  284.             &genericTypographicStringFormat->nativeFormat
  285.         );
  286.     return genericTypographicStringFormat;
  287. }
  288. #endif // !_GDIPLUSSTRINGFORMAT_H