Skip to main content
Skip table of contents

Color creation and conversion

📌 Overview

This Mako example shows how to create colors in different ways, including creating a spot color. It produces a PDF with colored blocks of the colors made.

⌨️ Sample Code

This sample produces a PDF with colored blocks of the colors made using the different methods. Full implementation available at ColorConversion.cpp.

Create colors

CPP
const auto jawsMako = IJawsMako::create();
IJawsMako::enableAllFeatures(jawsMako);
const auto cmm = IColorManager::get(jawsMako);

const auto deviceCmykSpace = IDOMColorSpaceDeviceCMYK::create(jawsMako);

// Create an LAB colour space with D65 white point and -128 to 127 ranges for a and b values
const auto labColorSpace = IDOMColorSpaceLAB::create(jawsMako, 0.9504f, 1.0f, 1.0888f, 0.0, 0.0, 0.0, -128, 127, -128, 127);

// Create a device CMYK colorspace from an ICC profile
const auto iccBasedColorSpace = IDOMColorSpaceICCBased::create(
    jawsMako, IDOMICCProfile::create(
        jawsMako, IInputStream::createFromFile(
            jawsMako, R"(C:\Windows\System32\spool\drivers\color\WebCoatedFOGRA28.icc)")));

// Create an LAB colour
const auto pantoneBlue072C_lab = IDOMColor::create(jawsMako, labColorSpace, 1.0, 17.64, 43.0, -76.0);

// Make a copy and convert to ICC space
auto pantoneBlue072C_fogra = clone(pantoneBlue072C_lab, jawsMako);
pantoneBlue072C_fogra->setColorSpace(iccBasedColorSpace,eRelativeColorimetric, eBPCDefault, jawsMako);

// Create colorants for a DeviceN color (spot color)
const IDOMColorSpaceDeviceN::CColorantInfo pantoneBlue072C("PANTONE BLUE 072 C", 3, 17.64, 43.0, -76.0);
IDOMColorSpaceDeviceN::CColorantInfoVect colorants;
colorants.append(pantoneBlue072C);

// Create a deviceN colour space
const auto deviceNSpace = IDOMColorSpaceDeviceN::create(jawsMako, colorants, labColorSpace);

// Create a spot
const auto pantoneBlue072C_spot = IDOMColor::create(jawsMako, deviceNSpace, 1.0, 1.0);

Use colors to make blocks

CPP
// Add content. Three blocks, using the colours we have created
IDOMBrushPtr solidBrush = IDOMSolidColorBrush::create(jawsMako, pantoneBlue072C_lab);
FRect swatchPositionAndSize = FRect(48.0, 192.0, 192.0, 192.0);
auto  swatch = IDOMPathNode::createFilled(jawsMako, IDOMPathGeometry::create(jawsMako, swatchPositionAndSize), solidBrush);
fixedPage->appendChild(swatch);

solidBrush = IDOMSolidColorBrush::create(jawsMako, pantoneBlue072C_spot);
swatchPositionAndSize = FRect(288.0, 192.0, 192.0, 192.0);
swatch = IDOMPathNode::createFilled(jawsMako, IDOMPathGeometry::create(jawsMako, swatchPositionAndSize), solidBrush);
fixedPage->appendChild(swatch);

solidBrush = IDOMSolidColorBrush::create(jawsMako, pantoneBlue072C_fogra);
swatchPositionAndSize = FRect(528.0, 192.0, 192.0, 192.0);
swatch = IDOMPathNode::createFilled(jawsMako, IDOMPathGeometry::create(jawsMako, swatchPositionAndSize), solidBrush);
fixedPage->appendChild(swatch);

☑️ Conclusion

The Mako SDK provides versatile methods for color creation and conversion, allowing users to work with various color spaces and profiles. By following the provided sample code, users can create colors in different ways, including spot colors, and convert them across color spaces. This capability is essential for producing accurate and consistent color outputs in PDFs.

📚 Additional Resources

If you need additional help, see our API documentation for detailed information on class/method usage, or raise a support ticket via our customer portal.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.