Home | History | Annotate | Download | only in fxge
      1 // Copyright 2017 PDFium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
      6 
      7 #ifndef CORE_FXGE_CFX_COLOR_H_
      8 #define CORE_FXGE_CFX_COLOR_H_
      9 
     10 #include "core/fpdfdoc/cpdf_formcontrol.h"
     11 #include "core/fxge/fx_dib.h"
     12 
     13 struct CFX_Color {
     14   static CFX_Color ParseColor(const CPDF_Array& array);
     15   static CFX_Color ParseColor(const ByteString& str);
     16 
     17   enum Type { kTransparent = 0, kGray, kRGB, kCMYK };
     18 
     19   explicit CFX_Color(FX_COLORREF ref)
     20       : CFX_Color(FXARGB_R(ref), FXARGB_G(ref), FXARGB_B(ref)) {}
     21 
     22   CFX_Color(int32_t type = CFX_Color::kTransparent,
     23             float color1 = 0.0f,
     24             float color2 = 0.0f,
     25             float color3 = 0.0f,
     26             float color4 = 0.0f)
     27       : nColorType(type),
     28         fColor1(color1),
     29         fColor2(color2),
     30         fColor3(color3),
     31         fColor4(color4) {}
     32 
     33   CFX_Color(int32_t r, int32_t g, int32_t b)
     34       : nColorType(CFX_Color::kRGB),
     35         fColor1(r / 255.0f),
     36         fColor2(g / 255.0f),
     37         fColor3(b / 255.0f),
     38         fColor4(0) {}
     39 
     40   CFX_Color(const CFX_Color&) = default;
     41 
     42   CFX_Color operator/(float fColorDivide) const;
     43   CFX_Color operator-(float fColorSub) const;
     44 
     45   CFX_Color ConvertColorType(int32_t other_nColorType) const;
     46 
     47   FX_COLORREF ToFXColor(int32_t nTransparency) const;
     48 
     49   void Reset() {
     50     nColorType = CFX_Color::kTransparent;
     51     fColor1 = 0.0f;
     52     fColor2 = 0.0f;
     53     fColor3 = 0.0f;
     54     fColor4 = 0.0f;
     55   }
     56 
     57   int32_t nColorType;
     58   float fColor1;
     59   float fColor2;
     60   float fColor3;
     61   float fColor4;
     62 };
     63 
     64 #endif  // CORE_FXGE_CFX_COLOR_H_
     65