设置 SetROP2 是否对打印机设备有效?

Is set SetROP2 valid for printer device?

我 draw/print 每两行 table 用突出显示的笔。

CPen pen(PS_SOLID,nPenWidth,crPrint);
CPen* pOldPen = pDC->SelectObject(&pen);            
pDC->SetROP2(R2_MASKPEN);
pDC->MoveTo(rc.left+m_cxPrinter,y);
pDC->LineTo(rc.right-m_cxPrinter,y);
pDC->SelectObject(pOldPen);

我现在遇到的问题是,对于某些打印机,这会覆盖所有底层文本,因此看不到任何文本。

“Microsoft Print to PDF”打印机存在同样的问题。

来自CDC::SetRop2 备注:

The drawing mode is for raster devices only; it does not apply to vector devices. Drawing modes are binary raster-operation codes representing all possible Boolean combinations of two variables, using the binary operators AND, OR, and XOR (exclusive OR), and the unary operation NOT.

我认为这不可能,因为 pdf 打印机不是矢量设备?

--

编辑: 添加额外的代码来为大家测试它:

void CTestPrintView::OnDraw(CDC* pDC)
{
    CTestPrintDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    if (!pDoc)
        return;

    int static c = 0;
    
    // Resourcen select
    CFont* pOldFont = (CFont*)pDC->SelectStockObject(DEVICE_DEFAULT_FONT);

    TEXTMETRIC tm;
    pDC->GetTextMetrics(&tm);
    int m_cxPrinter = tm.tmAveCharWidth;
    int m_cyPrinter = tm.tmHeight + tm.tmExternalLeading;


    ////////////////////
    // Print this
    //
    int x = 10;
    int y = 10;

    for (int i = 0; i < 10; i++)
    {
        CString str;
        str.Format(L"%d Hello, can you Print me? ", c++);
        pDC->TextOut(x, y += m_cyPrinter, str);

        if (i % 2)
            DrawLineColor(pDC, CRect(x, y - m_cyPrinter / 2, x + m_cxPrinter * 80, y + m_cyPrinter));
    }

    pDC->SelectObject(pOldFont);
}


void CTestPrintView::DrawLineColor(CDC* pDC, const CRect& rc)
{
    // Print Ok in Preview
    // Fails with some printers and with "Microsoft Print to PDF" printer

    long y = rc.top;
    int nPenWidth = rc.Height(); // / 2;
    CPen pen(PS_SOLID, nPenWidth, RGB(187, 255, 255));
    CPen* pOldPen = pDC->SelectObject(&pen);
    int nOldROP = pDC->SetROP2(R2_MASKPEN);
    pDC->MoveTo(rc.left, y);
    pDC->LineTo(rc.right, y);
    pDC->SetROP2(nOldROP);
    pDC->SelectObject(pOldPen);
}

11 个月后,问题仍然存在,但我现在找到了解决此问题的好方法。在 DrawLineColor() 的末尾,只需将 2x 行反转为 InvertRect(rc)

    .. 
    pDC->SetROP2(nOldROP);
    pDC->SelectObject(pOldPen);

    // Don't remove this 2 lines of code! 
    // I do not know why this works, but this solve some Printer Drivers Problems (incl. Microsoft Print to PDF)
    pDC->InvertRect(rc);        // ***
    pDC->InvertRect(rc);        // ***
}