Commit 2e585414937a31751c4b431e1e1be2563bef024e
1 parent
37105710
Use JSON::parse to initialize schema for json mode
Showing
1 changed file
with
126 additions
and
272 deletions
libqpdf/QPDFJob.cc
| ... | ... | @@ -1462,10 +1462,9 @@ QPDFJob::json_schema(std::set<std::string>* keys) |
| 1462 | 1462 | "version", JSON::makeString( |
| 1463 | 1463 | "JSON format serial number; increased for non-compatible changes")); |
| 1464 | 1464 | JSON j_params = schema.addDictionaryMember( |
| 1465 | - "parameters", JSON::makeDictionary()); | |
| 1466 | - j_params.addDictionaryMember( | |
| 1467 | - "decodelevel", JSON::makeString( | |
| 1468 | - "decode level used to determine stream filterability")); | |
| 1465 | + "parameters", JSON::parse(R"({ | |
| 1466 | + "decodelevel": "decode level used to determine stream filterability" | |
| 1467 | +})")); | |
| 1469 | 1468 | |
| 1470 | 1469 | bool all_keys = ((keys == 0) || keys->empty()); |
| 1471 | 1470 | |
| ... | ... | @@ -1482,297 +1481,152 @@ QPDFJob::json_schema(std::set<std::string>* keys) |
| 1482 | 1481 | if (all_keys || keys->count("objectinfo")) |
| 1483 | 1482 | { |
| 1484 | 1483 | JSON objectinfo = schema.addDictionaryMember( |
| 1485 | - "objectinfo", JSON::makeDictionary()); | |
| 1486 | - JSON details = objectinfo.addDictionaryMember( | |
| 1487 | - "<object-id>", JSON::makeDictionary()); | |
| 1488 | - JSON stream = details.addDictionaryMember( | |
| 1489 | - "stream", JSON::makeDictionary()); | |
| 1490 | - stream.addDictionaryMember( | |
| 1491 | - "is", | |
| 1492 | - JSON::makeString("whether the object is a stream")); | |
| 1493 | - stream.addDictionaryMember( | |
| 1494 | - "length", | |
| 1495 | - JSON::makeString("if stream, its length, otherwise null")); | |
| 1496 | - stream.addDictionaryMember( | |
| 1497 | - "filter", | |
| 1498 | - JSON::makeString("if stream, its filters, otherwise null")); | |
| 1484 | + "objectinfo", JSON::parse(R"({ | |
| 1485 | + "<object-id>": { | |
| 1486 | + "stream": { | |
| 1487 | + "filter": "if stream, its filters, otherwise null", | |
| 1488 | + "is": "whether the object is a stream", | |
| 1489 | + "length": "if stream, its length, otherwise null" | |
| 1490 | + } | |
| 1491 | + } | |
| 1492 | +})")); | |
| 1499 | 1493 | } |
| 1500 | 1494 | if (all_keys || keys->count("pages")) |
| 1501 | 1495 | { |
| 1502 | - JSON page = schema.addDictionaryMember("pages", JSON::makeArray()). | |
| 1503 | - addArrayElement(JSON::makeDictionary()); | |
| 1504 | - page.addDictionaryMember( | |
| 1505 | - "object", | |
| 1506 | - JSON::makeString("reference to original page object")); | |
| 1507 | - JSON image = page.addDictionaryMember("images", JSON::makeArray()). | |
| 1508 | - addArrayElement(JSON::makeDictionary()); | |
| 1509 | - image.addDictionaryMember( | |
| 1510 | - "name", | |
| 1511 | - JSON::makeString("name of image in XObject table")); | |
| 1512 | - image.addDictionaryMember( | |
| 1513 | - "object", | |
| 1514 | - JSON::makeString("reference to image stream")); | |
| 1515 | - image.addDictionaryMember( | |
| 1516 | - "width", | |
| 1517 | - JSON::makeString("image width")); | |
| 1518 | - image.addDictionaryMember( | |
| 1519 | - "height", | |
| 1520 | - JSON::makeString("image height")); | |
| 1521 | - image.addDictionaryMember( | |
| 1522 | - "colorspace", | |
| 1523 | - JSON::makeString("color space")); | |
| 1524 | - image.addDictionaryMember( | |
| 1525 | - "bitspercomponent", | |
| 1526 | - JSON::makeString("bits per component")); | |
| 1527 | - image.addDictionaryMember("filter", JSON::makeArray()). | |
| 1528 | - addArrayElement( | |
| 1529 | - JSON::makeString("filters applied to image data")); | |
| 1530 | - image.addDictionaryMember("decodeparms", JSON::makeArray()). | |
| 1531 | - addArrayElement( | |
| 1532 | - JSON::makeString("decode parameters for image data")); | |
| 1533 | - image.addDictionaryMember( | |
| 1534 | - "filterable", | |
| 1535 | - JSON::makeString("whether image data can be decoded" | |
| 1536 | - " using the decode level qpdf was invoked with")); | |
| 1537 | - page.addDictionaryMember("contents", JSON::makeArray()). | |
| 1538 | - addArrayElement( | |
| 1539 | - JSON::makeString("reference to each content stream")); | |
| 1540 | - page.addDictionaryMember( | |
| 1541 | - "label", | |
| 1542 | - JSON::makeString("page label dictionary, or null if none")); | |
| 1543 | - JSON outline = page.addDictionaryMember("outlines", JSON::makeArray()). | |
| 1544 | - addArrayElement(JSON::makeDictionary()); | |
| 1545 | - outline.addDictionaryMember( | |
| 1546 | - "object", | |
| 1547 | - JSON::makeString("reference to outline that targets this page")); | |
| 1548 | - outline.addDictionaryMember( | |
| 1549 | - "title", | |
| 1550 | - JSON::makeString("outline title")); | |
| 1551 | - outline.addDictionaryMember( | |
| 1552 | - "dest", | |
| 1553 | - JSON::makeString("outline destination dictionary")); | |
| 1554 | - page.addDictionaryMember( | |
| 1555 | - "pageposfrom1", | |
| 1556 | - JSON::makeString("position of page in document numbering from 1")); | |
| 1496 | + JSON page = schema.addDictionaryMember("pages", JSON::parse(R"([ | |
| 1497 | + { | |
| 1498 | + "contents": [ | |
| 1499 | + "reference to each content stream" | |
| 1500 | + ], | |
| 1501 | + "images": [ | |
| 1502 | + { | |
| 1503 | + "bitspercomponent": "bits per component", | |
| 1504 | + "colorspace": "color space", | |
| 1505 | + "decodeparms": [ | |
| 1506 | + "decode parameters for image data" | |
| 1507 | + ], | |
| 1508 | + "filter": [ | |
| 1509 | + "filters applied to image data" | |
| 1510 | + ], | |
| 1511 | + "filterable": "whether image data can be decoded using the decode level qpdf was invoked with", | |
| 1512 | + "height": "image height", | |
| 1513 | + "name": "name of image in XObject table", | |
| 1514 | + "object": "reference to image stream", | |
| 1515 | + "width": "image width" | |
| 1516 | + } | |
| 1517 | + ], | |
| 1518 | + "label": "page label dictionary, or null if none", | |
| 1519 | + "object": "reference to original page object", | |
| 1520 | + "outlines": [ | |
| 1521 | + { | |
| 1522 | + "dest": "outline destination dictionary", | |
| 1523 | + "object": "reference to outline that targets this page", | |
| 1524 | + "title": "outline title" | |
| 1525 | + } | |
| 1526 | + ], | |
| 1527 | + "pageposfrom1": "position of page in document numbering from 1" | |
| 1528 | + } | |
| 1529 | +])")); | |
| 1557 | 1530 | } |
| 1558 | 1531 | if (all_keys || keys->count("pagelabels")) |
| 1559 | 1532 | { |
| 1560 | 1533 | JSON labels = schema.addDictionaryMember( |
| 1561 | - "pagelabels", JSON::makeArray()). | |
| 1562 | - addArrayElement(JSON::makeDictionary()); | |
| 1563 | - labels.addDictionaryMember( | |
| 1564 | - "index", | |
| 1565 | - JSON::makeString("starting page position starting from zero")); | |
| 1566 | - labels.addDictionaryMember( | |
| 1567 | - "label", | |
| 1568 | - JSON::makeString("page label dictionary")); | |
| 1534 | + "pagelabels", JSON::parse(R"([ | |
| 1535 | + { | |
| 1536 | + "index": "starting page position starting from zero", | |
| 1537 | + "label": "page label dictionary" | |
| 1538 | + } | |
| 1539 | +])")); | |
| 1569 | 1540 | } |
| 1570 | 1541 | if (all_keys || keys->count("outlines")) |
| 1571 | 1542 | { |
| 1572 | 1543 | JSON outlines = schema.addDictionaryMember( |
| 1573 | - "outlines", JSON::makeArray()). | |
| 1574 | - addArrayElement(JSON::makeDictionary()); | |
| 1575 | - outlines.addDictionaryMember( | |
| 1576 | - "object", | |
| 1577 | - JSON::makeString("reference to this outline")); | |
| 1578 | - outlines.addDictionaryMember( | |
| 1579 | - "title", | |
| 1580 | - JSON::makeString("outline title")); | |
| 1581 | - outlines.addDictionaryMember( | |
| 1582 | - "dest", | |
| 1583 | - JSON::makeString("outline destination dictionary")); | |
| 1584 | - outlines.addDictionaryMember( | |
| 1585 | - "kids", | |
| 1586 | - JSON::makeString("array of descendent outlines")); | |
| 1587 | - outlines.addDictionaryMember( | |
| 1588 | - "open", | |
| 1589 | - JSON::makeString("whether the outline is displayed expanded")); | |
| 1590 | - outlines.addDictionaryMember( | |
| 1591 | - "destpageposfrom1", | |
| 1592 | - JSON::makeString("position of destination page in document" | |
| 1593 | - " numbered from 1; null if not known")); | |
| 1544 | + "outlines", JSON::parse(R"([ | |
| 1545 | + { | |
| 1546 | + "dest": "outline destination dictionary", | |
| 1547 | + "destpageposfrom1": "position of destination page in document numbered from 1; null if not known", | |
| 1548 | + "kids": "array of descendent outlines", | |
| 1549 | + "object": "reference to this outline", | |
| 1550 | + "open": "whether the outline is displayed expanded", | |
| 1551 | + "title": "outline title" | |
| 1552 | + } | |
| 1553 | +])")); | |
| 1594 | 1554 | } |
| 1595 | 1555 | if (all_keys || keys->count("acroform")) |
| 1596 | 1556 | { |
| 1597 | 1557 | JSON acroform = schema.addDictionaryMember( |
| 1598 | - "acroform", JSON::makeDictionary()); | |
| 1599 | - acroform.addDictionaryMember( | |
| 1600 | - "hasacroform", | |
| 1601 | - JSON::makeString("whether the document has interactive forms")); | |
| 1602 | - acroform.addDictionaryMember( | |
| 1603 | - "needappearances", | |
| 1604 | - JSON::makeString("whether the form fields' appearance" | |
| 1605 | - " streams need to be regenerated")); | |
| 1606 | - JSON fields = acroform.addDictionaryMember( | |
| 1607 | - "fields", JSON::makeArray()). | |
| 1608 | - addArrayElement(JSON::makeDictionary()); | |
| 1609 | - fields.addDictionaryMember( | |
| 1610 | - "object", | |
| 1611 | - JSON::makeString("reference to this form field")); | |
| 1612 | - fields.addDictionaryMember( | |
| 1613 | - "parent", | |
| 1614 | - JSON::makeString("reference to this field's parent")); | |
| 1615 | - fields.addDictionaryMember( | |
| 1616 | - "pageposfrom1", | |
| 1617 | - JSON::makeString("position of containing page numbered from 1")); | |
| 1618 | - fields.addDictionaryMember( | |
| 1619 | - "fieldtype", | |
| 1620 | - JSON::makeString("field type")); | |
| 1621 | - fields.addDictionaryMember( | |
| 1622 | - "fieldflags", | |
| 1623 | - JSON::makeString( | |
| 1624 | - "form field flags from /Ff --" | |
| 1625 | - " see pdf_form_field_flag_e in qpdf/Constants.h")); | |
| 1626 | - fields.addDictionaryMember( | |
| 1627 | - "fullname", | |
| 1628 | - JSON::makeString("full name of field")); | |
| 1629 | - fields.addDictionaryMember( | |
| 1630 | - "partialname", | |
| 1631 | - JSON::makeString("partial name of field")); | |
| 1632 | - fields.addDictionaryMember( | |
| 1633 | - "alternativename", | |
| 1634 | - JSON::makeString( | |
| 1635 | - "alternative name of field --" | |
| 1636 | - " this is the one usually shown to users")); | |
| 1637 | - fields.addDictionaryMember( | |
| 1638 | - "mappingname", | |
| 1639 | - JSON::makeString("mapping name of field")); | |
| 1640 | - fields.addDictionaryMember( | |
| 1641 | - "value", | |
| 1642 | - JSON::makeString("value of field")); | |
| 1643 | - fields.addDictionaryMember( | |
| 1644 | - "defaultvalue", | |
| 1645 | - JSON::makeString("default value of field")); | |
| 1646 | - fields.addDictionaryMember( | |
| 1647 | - "quadding", | |
| 1648 | - JSON::makeString( | |
| 1649 | - "field quadding --" | |
| 1650 | - " number indicating left, center, or right")); | |
| 1651 | - fields.addDictionaryMember( | |
| 1652 | - "ischeckbox", | |
| 1653 | - JSON::makeString("whether field is a checkbox")); | |
| 1654 | - fields.addDictionaryMember( | |
| 1655 | - "isradiobutton", | |
| 1656 | - JSON::makeString("whether field is a radio button --" | |
| 1657 | - " buttons in a single group share a parent")); | |
| 1658 | - fields.addDictionaryMember( | |
| 1659 | - "ischoice", | |
| 1660 | - JSON::makeString("whether field is a list, combo, or dropdown")); | |
| 1661 | - fields.addDictionaryMember( | |
| 1662 | - "istext", | |
| 1663 | - JSON::makeString("whether field is a text field")); | |
| 1664 | - JSON j_choices = fields.addDictionaryMember( | |
| 1665 | - "choices", | |
| 1666 | - JSON::makeString("for choices fields, the list of" | |
| 1667 | - " choices presented to the user")); | |
| 1668 | - JSON annotation = fields.addDictionaryMember( | |
| 1669 | - "annotation", JSON::makeDictionary()); | |
| 1670 | - annotation.addDictionaryMember( | |
| 1671 | - "object", | |
| 1672 | - JSON::makeString("reference to the annotation object")); | |
| 1673 | - annotation.addDictionaryMember( | |
| 1674 | - "appearancestate", | |
| 1675 | - JSON::makeString("appearance state --" | |
| 1676 | - " can be used to determine value for" | |
| 1677 | - " checkboxes and radio buttons")); | |
| 1678 | - annotation.addDictionaryMember( | |
| 1679 | - "annotationflags", | |
| 1680 | - JSON::makeString( | |
| 1681 | - "annotation flags from /F --" | |
| 1682 | - " see pdf_annotation_flag_e in qpdf/Constants.h")); | |
| 1558 | + "acroform", JSON::parse(R"({ | |
| 1559 | + "fields": [ | |
| 1560 | + { | |
| 1561 | + "alternativename": "alternative name of field -- this is the one usually shown to users", | |
| 1562 | + "annotation": { | |
| 1563 | + "annotationflags": "annotation flags from /F -- see pdf_annotation_flag_e in qpdf/Constants.h", | |
| 1564 | + "appearancestate": "appearance state -- can be used to determine value for checkboxes and radio buttons", | |
| 1565 | + "object": "reference to the annotation object" | |
| 1566 | + }, | |
| 1567 | + "choices": "for choices fields, the list of choices presented to the user", | |
| 1568 | + "defaultvalue": "default value of field", | |
| 1569 | + "fieldflags": "form field flags from /Ff -- see pdf_form_field_flag_e in qpdf/Constants.h", | |
| 1570 | + "fieldtype": "field type", | |
| 1571 | + "fullname": "full name of field", | |
| 1572 | + "ischeckbox": "whether field is a checkbox", | |
| 1573 | + "ischoice": "whether field is a list, combo, or dropdown", | |
| 1574 | + "isradiobutton": "whether field is a radio button -- buttons in a single group share a parent", | |
| 1575 | + "istext": "whether field is a text field", | |
| 1576 | + "mappingname": "mapping name of field", | |
| 1577 | + "object": "reference to this form field", | |
| 1578 | + "pageposfrom1": "position of containing page numbered from 1", | |
| 1579 | + "parent": "reference to this field's parent", | |
| 1580 | + "partialname": "partial name of field", | |
| 1581 | + "quadding": "field quadding -- number indicating left, center, or right", | |
| 1582 | + "value": "value of field" | |
| 1583 | + } | |
| 1584 | + ], | |
| 1585 | + "hasacroform": "whether the document has interactive forms", | |
| 1586 | + "needappearances": "whether the form fields' appearance streams need to be regenerated" | |
| 1587 | +})")); | |
| 1683 | 1588 | } |
| 1684 | 1589 | if (all_keys || keys->count("encrypt")) |
| 1685 | 1590 | { |
| 1686 | 1591 | JSON encrypt = schema.addDictionaryMember( |
| 1687 | - "encrypt", JSON::makeDictionary()); | |
| 1688 | - encrypt.addDictionaryMember( | |
| 1689 | - "encrypted", | |
| 1690 | - JSON::makeString("whether the document is encrypted")); | |
| 1691 | - encrypt.addDictionaryMember( | |
| 1692 | - "userpasswordmatched", | |
| 1693 | - JSON::makeString("whether supplied password matched user password;" | |
| 1694 | - " always false for non-encrypted files")); | |
| 1695 | - encrypt.addDictionaryMember( | |
| 1696 | - "ownerpasswordmatched", | |
| 1697 | - JSON::makeString("whether supplied password matched owner password;" | |
| 1698 | - " always false for non-encrypted files")); | |
| 1699 | - JSON capabilities = encrypt.addDictionaryMember( | |
| 1700 | - "capabilities", JSON::makeDictionary()); | |
| 1701 | - capabilities.addDictionaryMember( | |
| 1702 | - "accessibility", | |
| 1703 | - JSON::makeString("allow extraction for accessibility?")); | |
| 1704 | - capabilities.addDictionaryMember( | |
| 1705 | - "extract", | |
| 1706 | - JSON::makeString("allow extraction?")); | |
| 1707 | - capabilities.addDictionaryMember( | |
| 1708 | - "printlow", | |
| 1709 | - JSON::makeString("allow low resolution printing?")); | |
| 1710 | - capabilities.addDictionaryMember( | |
| 1711 | - "printhigh", | |
| 1712 | - JSON::makeString("allow high resolution printing?")); | |
| 1713 | - capabilities.addDictionaryMember( | |
| 1714 | - "modifyassembly", | |
| 1715 | - JSON::makeString("allow modifying document assembly?")); | |
| 1716 | - capabilities.addDictionaryMember( | |
| 1717 | - "modifyforms", | |
| 1718 | - JSON::makeString("allow modifying forms?")); | |
| 1719 | - capabilities.addDictionaryMember( | |
| 1720 | - "moddifyannotations", | |
| 1721 | - JSON::makeString("allow modifying annotations?")); | |
| 1722 | - capabilities.addDictionaryMember( | |
| 1723 | - "modifyother", | |
| 1724 | - JSON::makeString("allow other modifications?")); | |
| 1725 | - capabilities.addDictionaryMember( | |
| 1726 | - "modify", | |
| 1727 | - JSON::makeString("allow all modifications?")); | |
| 1728 | - | |
| 1729 | - JSON parameters = encrypt.addDictionaryMember( | |
| 1730 | - "parameters", JSON::makeDictionary()); | |
| 1731 | - parameters.addDictionaryMember( | |
| 1732 | - "R", | |
| 1733 | - JSON::makeString("R value from Encrypt dictionary")); | |
| 1734 | - parameters.addDictionaryMember( | |
| 1735 | - "V", | |
| 1736 | - JSON::makeString("V value from Encrypt dictionary")); | |
| 1737 | - parameters.addDictionaryMember( | |
| 1738 | - "P", | |
| 1739 | - JSON::makeString("P value from Encrypt dictionary")); | |
| 1740 | - parameters.addDictionaryMember( | |
| 1741 | - "bits", | |
| 1742 | - JSON::makeString("encryption key bit length")); | |
| 1743 | - parameters.addDictionaryMember( | |
| 1744 | - "key", | |
| 1745 | - JSON::makeString("encryption key; will be null" | |
| 1746 | - " unless --show-encryption-key was specified")); | |
| 1747 | - parameters.addDictionaryMember( | |
| 1748 | - "method", | |
| 1749 | - JSON::makeString("overall encryption method:" | |
| 1750 | - " none, mixed, RC4, AESv2, AESv3")); | |
| 1751 | - parameters.addDictionaryMember( | |
| 1752 | - "streammethod", | |
| 1753 | - JSON::makeString("encryption method for streams")); | |
| 1754 | - parameters.addDictionaryMember( | |
| 1755 | - "stringmethod", | |
| 1756 | - JSON::makeString("encryption method for string")); | |
| 1757 | - parameters.addDictionaryMember( | |
| 1758 | - "filemethod", | |
| 1759 | - JSON::makeString("encryption method for attachments")); | |
| 1592 | + "encrypt", JSON::parse(R"({ | |
| 1593 | + "capabilities": { | |
| 1594 | + "accessibility": "allow extraction for accessibility?", | |
| 1595 | + "extract": "allow extraction?", | |
| 1596 | + "moddifyannotations": "allow modifying annotations?", | |
| 1597 | + "modify": "allow all modifications?", | |
| 1598 | + "modifyassembly": "allow modifying document assembly?", | |
| 1599 | + "modifyforms": "allow modifying forms?", | |
| 1600 | + "modifyother": "allow other modifications?", | |
| 1601 | + "printhigh": "allow high resolution printing?", | |
| 1602 | + "printlow": "allow low resolution printing?" | |
| 1603 | + }, | |
| 1604 | + "encrypted": "whether the document is encrypted", | |
| 1605 | + "ownerpasswordmatched": "whether supplied password matched owner password; always false for non-encrypted files", | |
| 1606 | + "parameters": { | |
| 1607 | + "P": "P value from Encrypt dictionary", | |
| 1608 | + "R": "R value from Encrypt dictionary", | |
| 1609 | + "V": "V value from Encrypt dictionary", | |
| 1610 | + "bits": "encryption key bit length", | |
| 1611 | + "filemethod": "encryption method for attachments", | |
| 1612 | + "key": "encryption key; will be null unless --show-encryption-key was specified", | |
| 1613 | + "method": "overall encryption method: none, mixed, RC4, AESv2, AESv3", | |
| 1614 | + "streammethod": "encryption method for streams", | |
| 1615 | + "stringmethod": "encryption method for string" | |
| 1616 | + }, | |
| 1617 | + "userpasswordmatched": "whether supplied password matched user password; always false for non-encrypted files" | |
| 1618 | +})")); | |
| 1760 | 1619 | } |
| 1761 | 1620 | if (all_keys || keys->count("attachments")) |
| 1762 | 1621 | { |
| 1763 | 1622 | JSON attachments = schema.addDictionaryMember( |
| 1764 | - "attachments", JSON::makeDictionary()); | |
| 1765 | - JSON details = attachments.addDictionaryMember( | |
| 1766 | - "<attachment-key>", JSON::makeDictionary()); | |
| 1767 | - details.addDictionaryMember( | |
| 1768 | - "filespec", | |
| 1769 | - JSON::makeString("object containing the file spec")); | |
| 1770 | - details.addDictionaryMember( | |
| 1771 | - "preferredname", | |
| 1772 | - JSON::makeString("most preferred file name")); | |
| 1773 | - details.addDictionaryMember( | |
| 1774 | - "preferredcontents", | |
| 1775 | - JSON::makeString("most preferred embedded file stream")); | |
| 1623 | + "attachments", JSON::parse(R"({ | |
| 1624 | + "<attachment-key>": { | |
| 1625 | + "filespec": "object containing the file spec", | |
| 1626 | + "preferredcontents": "most preferred embedded file stream", | |
| 1627 | + "preferredname": "most preferred file name" | |
| 1628 | + } | |
| 1629 | +})")); | |
| 1776 | 1630 | } |
| 1777 | 1631 | return schema; |
| 1778 | 1632 | } | ... | ... |