Developer API Code Snippets

👨‍💻Code Snippets

Here are code examples for the new APIs mentioned on the List of changes page.

1. PCL5 Font-Selection Monitoring (MAKO-5743)

Purpose: Captures raw font-selection intent directly from the PCL5 stream prior to DOM normalization.

C++
#include <jawsmako/jawsmako.h>
#include <iostream>

using namespace JawsMako;

class CLoggingFontSelectionMonitor : public IPCL5FontSelectionMonitor
{
public:
    void selectByCriteria(const IDOMFontPtr& font,
                          int32 symbolSet,
                          eSpacing spacing,
                          double pitch,
                          double height,
                          uint16 style,
                          eStrokeWeight strokeWeight,
                          uint16 typeface,
                          uint32 resolution,
                          eLocation location) override
    {
        std::cout << "PCL5 font selected by criteria: typeface=" << typeface
                  << " symbolSet=" << symbolSet << " pitch=" << pitch << std::endl;
    }

    void selectById(const IDOMFontPtr& font, uint16 id) override
    {
        std::cout << "PCL5 font selected by numeric ID: " << id << std::endl;
    }

    void selectById(const IDOMFontPtr& font, RawString id) override
    {
        std::cout << "PCL5 font selected by string ID: " << id << std::endl;
    }
};

void openPclWithFontMonitoring(const IJawsMakoPtr& mako, const U8String& inputPath)
{
    auto pclInput = IPCL5Input::create(mako);
    pclInput->setFontSelectionMonitor(std::make_shared<CLoggingFontSelectionMonitor>());

    auto assembly = pclInput->open(inputPath);
}

2. XObject In-Place Inspection and Modification (MAKO-5593)

Purpose: Inspect and modify repeated Form XObject DOM elements in place without expanding every instance.

C++
#include <jawsmako/jawsmako.h>

using namespace JawsMako;

void recolorPathsInXObjects(const IJawsMakoPtr& mako,
                            const U8String& inputPath,
                            const U8String& outputPath)
{
    auto input = IPDFInput::create(mako);
    auto assembly = input->open(inputPath);
    auto fixedPage = assembly->getDocument()->getPage(0)->getContent();

    CEDLVector<IDOMNodePtr> groups;
    fixedPage->findChildrenOfType(eDOMTransparencyGroupNode, groups);

    for (uint32 i = 0; i < groups.size(); ++i)
    {
        auto group = edlobj2IDOMTransparencyGroup(groups[i]);
        if (!group) continue;

        PValue objectNumber;
        if (group->getProperty("GroupXObjectNum", objectNumber))
        {
            // Identify XObject by number
        }

        CEDLVector<IDOMNodePtr> paths;
        group->findChildrenOfType(eDOMPathNode, paths);

        for (uint32 j = 0; j < paths.size(); ++j)
        {
            auto path = edlobj2IDOMPath(paths[j]);
            if (!path) continue;

            auto black = IDOMColor::create(mako, IDOMColorSpaceDeviceCMYK::create(mako));
            black->setValue(3, 1.0); // 100% K
            path->setFillColor(black);
        }
    }

    auto output = IPDFOutput::create(mako);
    output->writeAssembly(assembly, outputPath);
}

3. Apex GPU Selection Query (MAKO-5840)

Purpose: Query available GPU adapters and verify the specific device chosen by Apex.

C++
#include <jawsmako/jawsmako.h>
#include <iostream>

using namespace JawsMako;

void logApexGpuChoice(const IJawsMakoPtr& mako)
{
    auto renderer = IApexRenderer::create(mako);

    auto gpus = IApexRenderer::enumerateGpus(mako);
    for (uint32 i = 0; i < gpus.size(); ++i)
    {
        std::cout << "Apex GPU[" << i << "]: " << gpus[i].name << std::endl;
    }

    auto selectedGpu = renderer->getSelectedGpu();
    std::cout << "Apex selected GPU: " << selectedGpu.name << std::endl;
}

4. Sampled Image / Texture Access in Apex Shaders (MAKO-5851)

Purpose: Enables custom GLSL fragment shaders to sample neighboring pixels using sampler2D textures (e.g. for custom screening, edge detection, and filtering).

#version 450
layout(binding = 0) uniform sampler2D cmykTexture;
layout(location = 0) out vec4 outColor;

void main()
{
    ivec2 p = ivec2(gl_FragCoord.xy);

    vec4 centre = texelFetch(cmykTexture, p, 0);
    vec4 left   = texelFetch(cmykTexture, p + ivec2(-1,  0), 0);
    vec4 right  = texelFetch(cmykTexture, p + ivec2( 1,  0), 0);
    vec4 above  = texelFetch(cmykTexture, p + ivec2( 0, -1), 0);
    vec4 below  = texelFetch(cmykTexture, p + ivec2( 0,  1), 0);

    outColor = (centre + left + right + above + below) / 5.0;
}

5. Direct PDF/X-4 Output & Presets (MAKO-5676)

Purpose: Output PDF/X-4 directly using the preset configuration.

C++
#include <jawsmako/jawsmako.h>

using namespace JawsMako;

void writePdfX4WithDirectOutput(const IJawsMakoPtr& mako,
                                const U8String& inputPath,
                                const U8String& outputPath)
{
    auto input = IPDFInput::create(mako);
    auto assembly = input->open(inputPath);

    auto output = IPDFOutput::create(mako);
    output->setPreset("PDF/X-4");
    output->writeAssembly(assembly, outputPath);
}

6. Multi-Threaded APO Transform Chains (MAKO-5859)

Purpose: Offload custom page transforms to Apex PDF Output's worker threads during document writing.

C++
#include <jawsmako/jawsmako.h>

using namespace JawsMako;

class COutputPreparationTransform : public IPageTransform
{
public:
    IDOMFixedPagePtr transform(const IDOMFixedPagePtr& page) override
    {
        // Thread-safe page transformation (flattening, normalization, cleanup)
        return page;
    }
};

void writeWithApoTransformChain(const IJawsMakoPtr& mako,
                                const IDocumentAssemblyPtr& assembly,
                                const U8String& outputPath)
{
    auto apo = IApexPDFOutput::create(mako);

    CEDLVector<IPageTransformPtr> transforms;
    transforms.append(std::make_shared<COutputPreparationTransform>());

    apo->setPageTransformChain(transforms);
    apo->writeAssembly(assembly, outputPath);
}