openframeworks / openFrameworks

openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
http://openframeworks.cc
Other
9.97k stars 2.55k forks source link

blendmodes do not save from ofCairoRenderer? #7339

Open GitBruno opened 1 year ago

GitBruno commented 1 year ago

The blend modes look good on screen but is not saved to PDF or SVG.

//--------------------------------------------------------------
void ofApp::draw(){
    ofBackground(ofColor(255,255,255));

    if (saveVector) {
        ofBeginSaveScreenAsPDF("blendMode_test.pdf", false);
    }

    ofEnableBlendMode(OF_BLENDMODE_MULTIPLY);
    ofSetColor(ofColor(80,40,255));
    ofDrawRectangle(0,0,100,100);
    ofDrawRectangle(50, 50, 100, 100);

    if (saveVector) {
        ofEndSaveScreenAsPDF();
        saveVector = false;
    }
}

//--------------------------------------------------------------
void ofApp::keyPressed(int key){
    if (key == OF_KEY_DOWN) {
        saveVector = true;
    }
}

Screenshot

dimitre commented 1 year ago

I've noticed a while ago that Cairo actually generate a raster image when using blend modes. it doesn't calculate using vectors so maybe this is why it is not saving. It is unfortunate, I love blend modes on vectors too

artificiel commented 1 year ago

hmm what are you looking at the PDF and SVG with? could you share your output files?

here is what i got (macOS12.6):

image

below the produced files. blendMode_test.pdf blendMode_test

artificiel commented 1 year ago

it however seems cairo ignores ofBackground() -- it needs an explicite rect to blend to white as the GL renderer does. moreover, it needs a call to ofEnableBlendMode to "activate" (perhaps there is a funny default cairo blendmode).

ofEnableBlendMode(OF_BLENDMODE_ALPHA);
 ofSetColor(ofColor(255,255,255));
 ofDrawRectangle(0,0,ofGetWidth()/2,ofGetHeight()/2);

blendMode_test.pdf blendMode_test

GitBruno commented 1 year ago

I am running Running Windows 11 Pro 22H2 and viewing the PDF (attached) with Acrobat Pro. I downloaded your file and that one looks perfect! Could it be a Mac/Windows difference? blendMode_test.pdf

artificiel commented 1 year ago

i confirm your blendMode_test.pdf is not transparent in macOS12. inspecting the PDF source shows similar files (both generated by cairo 1.14.12) but reveals a difference at line 18:

my version:

   /ExtGState <<
      /b2 << /BM /Normal >>
      /b14 << /BM /Multiply >>
      /a0 << /CA 1 /ca 1 >>
   >>

your version:

   /ExtGState <<
      /a0 << /CA 1 /ca 1 >>
   >>

i can also confirm generating on linux produces transparency. unfortunately i cannot test windows.

is there anybody else on windows that can try the squares code at the top? so we can confirm if it's a generalized platform issue or something specific to a configuration.

artificiel commented 1 year ago

@GitBruno perhaps post on the forum for a windows test request? (including a directly compilable .h and .cpp so it's painless). you can link to this issue in case some want the background info.

more people over there -- might get a quicker response than here (and maybe more variety also if it turns out to be specific to some parameter)