gvplugin_gdiplus.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*************************************************************************
  2. * Copyright (c) 2011 AT&T Intellectual Property
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: Details at https://graphviz.org
  9. *************************************************************************/
  10. #pragma once
  11. #include <memory>
  12. #include <vector>
  13. #include <windows.h>
  14. #include <gdiplus.h>
  15. typedef enum {
  16. FORMAT_NONE,
  17. FORMAT_METAFILE,
  18. FORMAT_BMP,
  19. FORMAT_EMF,
  20. FORMAT_EMFPLUS,
  21. FORMAT_GIF,
  22. FORMAT_JPEG,
  23. FORMAT_PNG,
  24. FORMAT_TIFF
  25. } format_type;
  26. /* RAII for GetDC/ReleaseDC */
  27. struct DeviceContext
  28. {
  29. HWND hwnd;
  30. HDC hdc;
  31. DeviceContext(HWND wnd = nullptr): hwnd(wnd), hdc(GetDC(wnd))
  32. {
  33. }
  34. ~DeviceContext()
  35. {
  36. ReleaseDC(hwnd, hdc);
  37. }
  38. };
  39. /* textlayout etc. */
  40. struct Layout
  41. {
  42. std::unique_ptr<Gdiplus::Font> font;
  43. std::vector<WCHAR> text;
  44. Layout(char *fontname, double fontsize, char* string);
  45. };
  46. static const int BYTES_PER_PIXEL = 4; /* bytes per pixel */
  47. void gdiplus_free_layout(void *layout);
  48. void UseGdiplus();
  49. const Gdiplus::StringFormat* GetGenericTypographic();
  50. void SaveBitmapToStream(Gdiplus::Bitmap &bitmap, IStream *stream, int format);