/////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2002-2025, Open Design Alliance (the "Alliance"). // All rights reserved. // // This software and its documentation and related materials are owned by // the Alliance. The software may only be incorporated into application // programs owned by members of the Alliance, subject to a signed // Membership Agreement and Supplemental Software License Agreement with the // Alliance. The structure and organization of this software are the valuable // trade secrets of the Alliance and its suppliers. The software is also // protected by copyright law and international treaty provisions. Application // programs incorporating this software must include the following statement // with their copyright notices: // // This application incorporates Open Design Alliance software pursuant to a license // agreement with Open Design Alliance. // Open Design Alliance Copyright (C) 2002-2025 by Open Design Alliance. // All rights reserved. // // By use of this software, its documentation or related materials, you // acknowledge and accept the above terms. /////////////////////////////////////////////////////////////////////////////// // PlotStampWMarkDialog.cpp : implementation file // #include "stdafx.h" #include "PlotStampWMarkDialog.h" #include "ColorPickerDlg.h" #include "PdfImportTextOptDialog.h" using namespace TD_PDF_2D_EXPORT; PlotStampWMarkDialog::PlotStampWMarkDialog(Watermark* watermark, unsigned int iPageCount, CWnd* pParent /*=nullptr*/) : CDialog(PlotStampWMarkDialog::IDD, pParent) , m_Watermark(watermark) , m_iPageCount(iPageCount) , m_bFitWm2Page(FALSE) , m_bWmUpsideDown(FALSE) , m_bWmarkModeImg(0) //text mode { } PlotStampWMarkDialog::~PlotStampWMarkDialog() { } void PlotStampWMarkDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Text(pDX, IDC_WATERMARK, m_wmText); DDX_Text(pDX, IDC_EDIT_WM_FONTSIZE, m_iWMFontSize); DDX_Text(pDX, IDC_EDIT_WM_OPACITY, m_iWMOpacity); DDX_Text(pDX, IDC_WM_EDIT_XOFFSET, m_iWMXOffset); DDX_Text(pDX, IDC_WM_EDIT_YOFFSET, m_iWMYOffset); DDX_Text(pDX, IDC_WM_EDIT_ROTATION, m_iWMRotation); DDX_Text(pDX, IDC_EDIT_WM_IMAGE_W, m_iWMImageWidth); DDX_Text(pDX, IDC_EDIT_WM_IMAGE_H, m_iWMImageHeight); DDX_Check(pDX, IDC_CHECK_FIT_WM_2_PAGE, m_bFitWm2Page); DDX_Check(pDX, IDC_CHECK_WM_UPSIDE_DOWN, m_bWmUpsideDown); DDX_Control(pDX, IDC_COMBO_WM_POSITION, m_comboWMPosition); DDX_Control(pDX, IDC_COMBO_WM_ORIENTATION, m_comboWMOrientation); DDX_Control(pDX, IDC_COMBO_WM_FONT, m_comboWMFont); DDX_Control(pDX, IDC_COMBO_WM_FONT_COLOR, m_comboWMColor); DDX_Control(pDX, IDC_COMBO_WM_PAGE, m_comboWMPage); } BEGIN_MESSAGE_MAP(PlotStampWMarkDialog, CDialog) ON_BN_CLICKED(IDOK, OnOk) ON_CBN_SELCHANGE(IDC_COMBO_WM_FONT_COLOR, OnSelChangeWMarkColor) ON_CBN_SELCHANGE(IDC_COMBO_WM_POSITION, OnSelChangeWMarkPosition) ON_BN_CLICKED(IDC_BUTTON_WM_IMAGE, &PlotStampWMarkDialog::OnBnClickedButtonWmImage) ON_BN_CLICKED(IDC_CHECK_FIT_WM_2_PAGE, &PlotStampWMarkDialog::OnBnClickedCheckFitWm2Page) END_MESSAGE_MAP() void PlotStampWMarkDialog::OnSelChangeWMarkColor() { UpdateData(); if(m_comboWMColor.GetCurSel() == 3) { CColorPickerDlg dlg; if(dlg.DoModal() == IDOK) m_Watermark->color = dlg.GetColor(); } } void PlotStampWMarkDialog::OnSelChangeWMarkPosition() { if(!m_bWmarkModeImg) { UpdateData(); if(m_comboWMPosition.GetCurSel() == 1 || m_comboWMPosition.GetCurSel() == 2) { GetDlgItem(IDC_COMBO_WM_ORIENTATION)->EnableWindow(FALSE); GetDlgItem(IDC_WM_EDIT_ROTATION)->EnableWindow(FALSE); } else { GetDlgItem(IDC_COMBO_WM_ORIENTATION)->EnableWindow(TRUE); GetDlgItem(IDC_WM_EDIT_ROTATION)->EnableWindow(TRUE); } } } void PlotStampWMarkDialog::fillPosition() { m_comboWMPosition.ResetContent(); if (!m_bWmarkModeImg) { m_comboWMPosition.InsertString(0, _T("Left to right in page's center")); m_comboWMPosition.InsertString(1, _T("Upper left corner to lower right corner")); m_comboWMPosition.InsertString(2, _T("Lower left corner to upper right corner")); m_comboWMPosition.InsertString(3, _T("Upper left corner")); m_comboWMPosition.InsertString(4, _T("Upper right corner")); m_comboWMPosition.InsertString(5, _T("Lower right corner")); m_comboWMPosition.InsertString(6, _T("Lower left corner")); m_comboWMPosition.InsertString(7, _T("Header in page center")); m_comboWMPosition.InsertString(8, _T("Footer in page center")); m_comboWMPosition.InsertString(9, _T("Near left side in page center")); m_comboWMPosition.InsertString(10, _T("Near right side in page center")); } else { m_comboWMPosition.InsertString(0, _T("Page's center")); m_comboWMPosition.InsertString(1, _T("Upper left corner")); m_comboWMPosition.InsertString(2, _T("Upper right corner")); m_comboWMPosition.InsertString(3, _T("Lower right corner")); m_comboWMPosition.InsertString(4, _T("Lower left corner")); m_comboWMPosition.InsertString(5, _T("Header in page center")); m_comboWMPosition.InsertString(6, _T("Footer in page center")); m_comboWMPosition.InsertString(7, _T("Near left side in page center")); m_comboWMPosition.InsertString(8, _T("Near right side in page center")); } m_comboWMPosition.SetCurSel(0); } BOOL PlotStampWMarkDialog::OnInitDialog() { if(!CDialog::OnInitDialog()) return FALSE; GetDlgItem(IDC_EDIT_WM_IMAGE_W)->EnableWindow(FALSE); GetDlgItem(IDC_EDIT_WM_IMAGE_H)->EnableWindow(FALSE); GetDlgItem(IDC_STATIC_WM_IMAGE_PATH)->SetWindowText(_T("")); m_comboWMColor.ResetContent(); m_comboWMColor.InsertString(0, _T("Red")); m_comboWMColor.InsertString(1, _T("Green")); m_comboWMColor.InsertString(2, _T("Blue")); m_comboWMColor.InsertString(3, _T("Select color...")); m_comboWMColor.SetCurSel(0); fillPosition(); m_comboWMOrientation.ResetContent(); m_comboWMOrientation.InsertString(0, _T("Horizontal")); m_comboWMOrientation.InsertString(1, _T("Vertical")); m_comboWMOrientation.SetCurSel(0); m_comboWMFont.ResetContent(); m_comboWMFont.InsertString(0, _T("Pdf embedded: Times Roman")); m_comboWMFont.InsertString(1, _T("Pdf embedded: Helvetica")); m_comboWMFont.InsertString(2, _T("Pdf embedded: Courier")); m_comboWMFont.InsertString(3, _T("Pdf embedded: Symbol")); m_comboWMFont.InsertString(4, _T("Pdf embedded: Times Bold")); m_comboWMFont.InsertString(5, _T("Pdf embedded: Helvetica Bold")); m_comboWMFont.InsertString(6, _T("Pdf embedded: Courier Bold")); m_comboWMFont.InsertString(7, _T("Pdf embedded: ZapfDingbats")); m_comboWMFont.InsertString(8, _T("Pdf embedded: Times Italic")); m_comboWMFont.InsertString(9, _T("Pdf embedded: Helvetica Oblique")); m_comboWMFont.InsertString(10, _T("Pdf embedded: Courier Oblique")); m_comboWMFont.InsertString(11, _T("Pdf embedded: Times Bold Italic")); m_comboWMFont.InsertString(12, _T("Pdf embedded: Helvetica Bold Oblique")); m_comboWMFont.InsertString(13, _T("Pdf embedded: Courier Bold Oblique")); ////////////////////////////////////////////////////////////////////////// initFontsSet(m_hWnd); for(std::set::const_iterator iter = SystemFontsSet.begin(); iter != SystemFontsSet.end(); ++iter) { const int idx = (int)std::distance(static_cast::const_iterator>(SystemFontsSet.begin()), iter); m_comboWMFont.InsertString(idx + 14, *iter); } ////////////////////////////////////////////////////////////////////////// m_comboWMFont.SetCurSel(0); if (m_iPageCount < 2) { GetDlgItem(IDC_STATIC_WM_PAGE)->ShowWindow(FALSE); GetDlgItem(IDC_COMBO_WM_PAGE)->ShowWindow(FALSE); } else { m_comboWMPage.ResetContent(); m_comboWMPage.InsertString(0, _T("Every page")); for(unsigned int i = 0; i < m_iPageCount; i++) { CString page; page.Format(_T("Page %i"), i + 1); m_comboWMPage.InsertString(i + 1, page); } m_comboWMPage.SetCurSel(0); } m_iWMFontSize = 40; m_iWMOpacity = 50; m_iWMRotation = 0; m_iWMXOffset = 0; m_iWMYOffset = 0; m_iWMImageWidth = 0; m_iWMImageHeight = 0; UpdateData(FALSE); return TRUE; } void PlotStampWMarkDialog::OnOk() { UpdateData(TRUE); if(m_iWMOpacity > 100) m_iWMOpacity = 100; else if(m_iWMOpacity < 0) m_iWMOpacity = 0; m_Watermark->opacity = m_iWMOpacity; if(m_iWMFontSize > 72) m_iWMFontSize = 72; else if(m_iWMFontSize < 0) m_iWMFontSize = 0; m_Watermark->fontSize = m_iWMFontSize; //if(m_wmText.GetLength() > 15) //m_wmText.Truncate(15); m_Watermark->text = m_wmText; switch(m_comboWMColor.GetCurSel()) { case 0: m_Watermark->color = ODRGB(255, 0, 0); break; case 1: m_Watermark->color = ODRGB(0, 255, 0); break; case 2: m_Watermark->color = ODRGB(0, 0, 255); break; default: break; } int fontIndex = m_comboWMFont.GetCurSel(); if(fontIndex > Watermark::WatermarkFonts::kCourierBoldOblique) { fontIndex = -1; CString tmp; m_comboWMFont.GetLBText(m_comboWMFont.GetCurSel(), tmp); m_Watermark->fontName = tmp; } m_Watermark->font = (Watermark::WatermarkFonts)fontIndex; if(!m_bWmarkModeImg) m_Watermark->position = (Watermark::WatermarkPosition)m_comboWMPosition.GetCurSel(); else { if(m_comboWMPosition.GetCurSel() == 0) m_Watermark->position = Watermark::kLeftToRight; else m_Watermark->position = (Watermark::WatermarkPosition)(m_comboWMPosition.GetCurSel() + 2); } m_Watermark->scaleToPage = m_bFitWm2Page != 0; m_Watermark->rotation = 0; if(m_Watermark->position != Watermark::kUpperLeftToLowerRight && m_Watermark->position != Watermark::kLowerLeftToUpperRight) { m_Watermark->rotation = OdaToRadian(m_iWMRotation); if(m_comboWMOrientation.GetCurSel()) //vertical m_Watermark->rotation += OdaPI2; } if(m_bWmUpsideDown) m_Watermark->rotation += OdaPI; m_Watermark->offset.x = m_iWMXOffset; m_Watermark->offset.y = m_iWMYOffset; m_Watermark->imageWidth = m_iWMImageWidth; m_Watermark->imageHeight = m_iWMImageHeight; if(m_iPageCount < 2) m_Watermark->pageIndex = -1; else m_Watermark->pageIndex = m_comboWMPage.GetCurSel() - 1; CDialog::OnOK(); } void PlotStampWMarkDialog::OnBnClickedButtonWmImage() { if (!m_bWmarkModeImg) //text mode { CString sImagePath; CFileDialog openFile(true, _T("png"), sImagePath, OFN_PATHMUSTEXIST, _T("JPEG Images (*.jpg)|*.jpg|") _T("Windows Bitmap (*.bmp)|*.bmp|Portable Network Graphics (*.png)|*.png|TARGA Images (*.tga)|*.tga|All Files (*.*)|*.*||"), this); if(openFile.DoModal() == IDOK) { m_Watermark->imagePath = openFile.GetPathName(); OdRxSystemServices* pSs = odrxSystemServices(); if(pSs->accessFile(m_Watermark->imagePath, Oda::kFileRead)) { if(!m_bFitWm2Page) { GetDlgItem(IDC_EDIT_WM_IMAGE_W)->EnableWindow(TRUE); GetDlgItem(IDC_EDIT_WM_IMAGE_H)->EnableWindow(TRUE); } else { GetDlgItem(IDC_EDIT_WM_IMAGE_W)->EnableWindow(FALSE); GetDlgItem(IDC_EDIT_WM_IMAGE_H)->EnableWindow(FALSE); } GetDlgItem(IDC_COMBO_WM_ORIENTATION)->EnableWindow(TRUE); GetDlgItem(IDC_WM_EDIT_ROTATION)->EnableWindow(TRUE); GetDlgItem(IDC_WATERMARK)->EnableWindow(FALSE); GetDlgItem(IDC_COMBO_WM_FONT)->EnableWindow(FALSE); GetDlgItem(IDC_COMBO_WM_FONT_COLOR)->EnableWindow(FALSE); GetDlgItem(IDC_EDIT_WM_FONTSIZE)->EnableWindow(FALSE); GetDlgItem(IDC_STATIC_WM_IMAGE_PATH)->SetWindowText(openFile.GetPathName()); GetDlgItem(IDC_BUTTON_WM_IMAGE)->SetWindowText(_T("Remove Image")); m_bWmarkModeImg = !m_bWmarkModeImg; fillPosition(); m_iWMImageWidth = 50; m_iWMImageHeight = 50; } } } else { m_Watermark->imagePath.empty(); GetDlgItem(IDC_EDIT_WM_IMAGE_W)->EnableWindow(FALSE); GetDlgItem(IDC_EDIT_WM_IMAGE_H)->EnableWindow(FALSE); GetDlgItem(IDC_WATERMARK)->EnableWindow(TRUE); GetDlgItem(IDC_COMBO_WM_FONT)->EnableWindow(TRUE); GetDlgItem(IDC_COMBO_WM_FONT_COLOR)->EnableWindow(TRUE); if(!m_bFitWm2Page) GetDlgItem(IDC_EDIT_WM_FONTSIZE)->EnableWindow(TRUE); else GetDlgItem(IDC_EDIT_WM_FONTSIZE)->EnableWindow(FALSE); GetDlgItem(IDC_BUTTON_WM_IMAGE)->SetWindowText(_T("Load Image...")); GetDlgItem(IDC_STATIC_WM_IMAGE_PATH)->SetWindowText(_T("")); m_bWmarkModeImg = !m_bWmarkModeImg; fillPosition(); m_iWMImageWidth = 0; m_iWMImageHeight = 0; } UpdateData(FALSE); } void PlotStampWMarkDialog::OnBnClickedCheckFitWm2Page() { UpdateData(TRUE); if(m_bFitWm2Page) { if(m_bWmarkModeImg) { GetDlgItem(IDC_EDIT_WM_IMAGE_W)->EnableWindow(FALSE); GetDlgItem(IDC_EDIT_WM_IMAGE_H)->EnableWindow(FALSE); } else GetDlgItem(IDC_EDIT_WM_FONTSIZE)->EnableWindow(FALSE); } else { if(m_bWmarkModeImg) { GetDlgItem(IDC_EDIT_WM_IMAGE_W)->EnableWindow(TRUE); GetDlgItem(IDC_EDIT_WM_IMAGE_H)->EnableWindow(TRUE); } else GetDlgItem(IDC_EDIT_WM_FONTSIZE)->EnableWindow(TRUE); } }