1 /* 2 ============================================================================== 3 4 This file is part of the JUCE library. 5 Copyright (c) 2020 - Raw Material Software Limited 6 7 JUCE is an open source library subject to commercial or open-source 8 licensing. 9 10 By using JUCE, you agree to the terms of both the JUCE 6 End-User License 11 Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020). 12 13 End User License Agreement: www.juce.com/juce-6-licence 14 Privacy Policy: www.juce.com/juce-privacy-policy 15 16 Or: You may also use this code under the terms of the GPL v3 (see 17 www.gnu.org/licenses). 18 19 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER 20 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE 21 DISCLAIMED. 22 23 ============================================================================== 24 */ 25 26 namespace juce 27 { 28 29 //============================================================================== 30 /** 31 An implementation of LowLevelGraphicsContext that turns the drawing operations 32 into a PostScript document. 33 34 @tags{Graphics} 35 */ 36 class JUCE_API LowLevelGraphicsPostScriptRenderer : public LowLevelGraphicsContext 37 { 38 public: 39 //============================================================================== 40 LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript, 41 const String& documentTitle, 42 int totalWidth, 43 int totalHeight); 44 45 ~LowLevelGraphicsPostScriptRenderer() override; 46 47 //============================================================================== 48 bool isVectorDevice() const override; 49 void setOrigin (Point<int>) override; 50 void addTransform (const AffineTransform&) override; 51 float getPhysicalPixelScaleFactor() override; 52 53 bool clipToRectangle (const Rectangle<int>&) override; 54 bool clipToRectangleList (const RectangleList<int>&) override; 55 void excludeClipRectangle (const Rectangle<int>&) override; 56 void clipToPath (const Path&, const AffineTransform&) override; 57 void clipToImageAlpha (const Image&, const AffineTransform&) override; 58 59 void saveState() override; 60 void restoreState() override; 61 62 void beginTransparencyLayer (float) override; 63 void endTransparencyLayer() override; 64 65 bool clipRegionIntersects (const Rectangle<int>&) override; 66 Rectangle<int> getClipBounds() const override; 67 bool isClipEmpty() const override; 68 69 //============================================================================== 70 void setFill (const FillType&) override; 71 void setOpacity (float) override; 72 void setInterpolationQuality (Graphics::ResamplingQuality) override; 73 74 //============================================================================== 75 void fillRect (const Rectangle<int>&, bool replaceExistingContents) override; 76 void fillRect (const Rectangle<float>&) override; 77 void fillRectList (const RectangleList<float>&) override; 78 void fillPath (const Path&, const AffineTransform&) override; 79 void drawImage (const Image&, const AffineTransform&) override; 80 void drawLine (const Line <float>&) override; 81 82 //============================================================================== 83 const Font& getFont() override; 84 void setFont (const Font&) override; 85 void drawGlyph (int glyphNumber, const AffineTransform&) override; 86 87 protected: 88 //============================================================================== 89 OutputStream& out; 90 int totalWidth, totalHeight; 91 bool needToClip; 92 Colour lastColour; 93 94 /** Describes a saved state */ 95 struct SavedState 96 { 97 SavedState(); 98 SavedState& operator= (const SavedState&) = delete; 99 ~SavedState(); 100 101 RectangleList<int> clip; 102 int xOffset, yOffset; 103 FillType fillType; 104 Font font; 105 }; 106 107 OwnedArray<SavedState> stateStack; 108 109 void writeClip(); 110 void writeColour (Colour colour); 111 void writePath (const Path&) const; 112 void writeXY (float x, float y) const; 113 void writeTransform (const AffineTransform&) const; 114 void writeImage (const Image&, int sx, int sy, int maxW, int maxH) const; 115 116 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LowLevelGraphicsPostScriptRenderer) 117 }; 118 119 } // namespace juce 120