-rw-r--r-- | noncore/unsupported/qpdf/xpdf/Gfx.cc | 2 | ||||
-rw-r--r-- | noncore/unsupported/qpdf/xpdf/Object.cc | 2 | ||||
-rw-r--r-- | noncore/unsupported/qpdf/xpdf/Page.cc | 4 |
3 files changed, 4 insertions, 4 deletions
diff --git a/noncore/unsupported/qpdf/xpdf/Gfx.cc b/noncore/unsupported/qpdf/xpdf/Gfx.cc index 17d613e..f016c0e 100644 --- a/noncore/unsupported/qpdf/xpdf/Gfx.cc +++ b/noncore/unsupported/qpdf/xpdf/Gfx.cc | |||
@@ -1675,385 +1675,385 @@ void Gfx::doRadialShFill(GfxRadialShading *shading) { | |||
1675 | ctm = state->getCTM(); | 1675 | ctm = state->getCTM(); |
1676 | t = fabs(ctm[0]); | 1676 | t = fabs(ctm[0]); |
1677 | if (fabs(ctm[1]) > t) { | 1677 | if (fabs(ctm[1]) > t) { |
1678 | t = fabs(ctm[1]); | 1678 | t = fabs(ctm[1]); |
1679 | } | 1679 | } |
1680 | if (fabs(ctm[2]) > t) { | 1680 | if (fabs(ctm[2]) > t) { |
1681 | t = fabs(ctm[2]); | 1681 | t = fabs(ctm[2]); |
1682 | } | 1682 | } |
1683 | if (fabs(ctm[3]) > t) { | 1683 | if (fabs(ctm[3]) > t) { |
1684 | t = fabs(ctm[3]); | 1684 | t = fabs(ctm[3]); |
1685 | } | 1685 | } |
1686 | if (r0 > r1) { | 1686 | if (r0 > r1) { |
1687 | t *= r0; | 1687 | t *= r0; |
1688 | } else { | 1688 | } else { |
1689 | t *= r1; | 1689 | t *= r1; |
1690 | } | 1690 | } |
1691 | if (t < 1) { | 1691 | if (t < 1) { |
1692 | n = 3; | 1692 | n = 3; |
1693 | } else { | 1693 | } else { |
1694 | n = (int)(M_PI / acos(1 - 0.1 / t)); | 1694 | n = (int)(M_PI / acos(1 - 0.1 / t)); |
1695 | if (n < 3) { | 1695 | if (n < 3) { |
1696 | n = 3; | 1696 | n = 3; |
1697 | } else if (n > 200) { | 1697 | } else if (n > 200) { |
1698 | n = 200; | 1698 | n = 200; |
1699 | } | 1699 | } |
1700 | } | 1700 | } |
1701 | 1701 | ||
1702 | // Traverse the t axis and do the shading. | 1702 | // Traverse the t axis and do the shading. |
1703 | // | 1703 | // |
1704 | // This generates and fills a series of rings. Each ring is defined | 1704 | // This generates and fills a series of rings. Each ring is defined |
1705 | // by two circles: | 1705 | // by two circles: |
1706 | // sa, ta, xa, ya, ra, colorA | 1706 | // sa, ta, xa, ya, ra, colorA |
1707 | // sb, tb, xb, yb, rb, colorB | 1707 | // sb, tb, xb, yb, rb, colorB |
1708 | // | 1708 | // |
1709 | // The s/t axis is divided into radialMaxSplits parts; these parts | 1709 | // The s/t axis is divided into radialMaxSplits parts; these parts |
1710 | // are combined as much as possible while respecting the | 1710 | // are combined as much as possible while respecting the |
1711 | // radialColorDelta parameter. | 1711 | // radialColorDelta parameter. |
1712 | 1712 | ||
1713 | // setup for the start circle | 1713 | // setup for the start circle |
1714 | ia = 0; | 1714 | ia = 0; |
1715 | sa = sMin; | 1715 | sa = sMin; |
1716 | ta = t0 + sa * (t1 - t0); | 1716 | ta = t0 + sa * (t1 - t0); |
1717 | xa = x0 + sa * (x1 - x0); | 1717 | xa = x0 + sa * (x1 - x0); |
1718 | ya = y0 + sa * (y1 - y0); | 1718 | ya = y0 + sa * (y1 - y0); |
1719 | ra = r0 + sa * (r1 - r0); | 1719 | ra = r0 + sa * (r1 - r0); |
1720 | if (ta < t0) { | 1720 | if (ta < t0) { |
1721 | shading->getColor(t0, &colorA); | 1721 | shading->getColor(t0, &colorA); |
1722 | } else if (ta > t1) { | 1722 | } else if (ta > t1) { |
1723 | shading->getColor(t1, &colorA); | 1723 | shading->getColor(t1, &colorA); |
1724 | } else { | 1724 | } else { |
1725 | shading->getColor(ta, &colorA); | 1725 | shading->getColor(ta, &colorA); |
1726 | } | 1726 | } |
1727 | 1727 | ||
1728 | while (ia < radialMaxSplits) { | 1728 | while (ia < radialMaxSplits) { |
1729 | 1729 | ||
1730 | // go as far along the t axis (toward t1) as we can, such that the | 1730 | // go as far along the t axis (toward t1) as we can, such that the |
1731 | // color difference is within the tolerance (radialColorDelta) -- | 1731 | // color difference is within the tolerance (radialColorDelta) -- |
1732 | // this uses bisection (between the current value, t, and t1), | 1732 | // this uses bisection (between the current value, t, and t1), |
1733 | // limited to radialMaxSplits points along the t axis | 1733 | // limited to radialMaxSplits points along the t axis |
1734 | ib = radialMaxSplits; | 1734 | ib = radialMaxSplits; |
1735 | sb = sMin + ((fouble)ib / (fouble)radialMaxSplits) * (sMax - sMin); | 1735 | sb = sMin + ((fouble)ib / (fouble)radialMaxSplits) * (sMax - sMin); |
1736 | tb = t0 + sb * (t1 - t0); | 1736 | tb = t0 + sb * (t1 - t0); |
1737 | if (tb < t0) { | 1737 | if (tb < t0) { |
1738 | shading->getColor(t0, &colorB); | 1738 | shading->getColor(t0, &colorB); |
1739 | } else if (tb > t1) { | 1739 | } else if (tb > t1) { |
1740 | shading->getColor(t1, &colorB); | 1740 | shading->getColor(t1, &colorB); |
1741 | } else { | 1741 | } else { |
1742 | shading->getColor(tb, &colorB); | 1742 | shading->getColor(tb, &colorB); |
1743 | } | 1743 | } |
1744 | while (ib - ia > 1) { | 1744 | while (ib - ia > 1) { |
1745 | for (k = 0; k < nComps; ++k) { | 1745 | for (k = 0; k < nComps; ++k) { |
1746 | if (fabs(colorB.c[k] - colorA.c[k]) > radialColorDelta) { | 1746 | if (fabs(colorB.c[k] - colorA.c[k]) > radialColorDelta) { |
1747 | break; | 1747 | break; |
1748 | } | 1748 | } |
1749 | } | 1749 | } |
1750 | if (k == nComps) { | 1750 | if (k == nComps) { |
1751 | break; | 1751 | break; |
1752 | } | 1752 | } |
1753 | ib = (ia + ib) / 2; | 1753 | ib = (ia + ib) / 2; |
1754 | sb = sMin + ((fouble)ib / (fouble)radialMaxSplits) * (sMax - sMin); | 1754 | sb = sMin + ((fouble)ib / (fouble)radialMaxSplits) * (sMax - sMin); |
1755 | tb = t0 + sb * (t1 - t0); | 1755 | tb = t0 + sb * (t1 - t0); |
1756 | if (tb < t0) { | 1756 | if (tb < t0) { |
1757 | shading->getColor(t0, &colorB); | 1757 | shading->getColor(t0, &colorB); |
1758 | } else if (tb > t1) { | 1758 | } else if (tb > t1) { |
1759 | shading->getColor(t1, &colorB); | 1759 | shading->getColor(t1, &colorB); |
1760 | } else { | 1760 | } else { |
1761 | shading->getColor(tb, &colorB); | 1761 | shading->getColor(tb, &colorB); |
1762 | } | 1762 | } |
1763 | } | 1763 | } |
1764 | 1764 | ||
1765 | // compute center and radius of the circle | 1765 | // compute center and radius of the circle |
1766 | xb = x0 + sb * (x1 - x0); | 1766 | xb = x0 + sb * (x1 - x0); |
1767 | yb = y0 + sb * (y1 - y0); | 1767 | yb = y0 + sb * (y1 - y0); |
1768 | rb = r0 + sb * (r1 - r0); | 1768 | rb = r0 + sb * (r1 - r0); |
1769 | 1769 | ||
1770 | // use the average of the colors at the two circles | 1770 | // use the average of the colors at the two circles |
1771 | for (k = 0; k < nComps; ++k) { | 1771 | for (k = 0; k < nComps; ++k) { |
1772 | colorA.c[k] = 0.5 * (colorA.c[k] + colorB.c[k]); | 1772 | colorA.c[k] = 0.5 * (colorA.c[k] + colorB.c[k]); |
1773 | } | 1773 | } |
1774 | state->setFillColor(&colorA); | 1774 | state->setFillColor(&colorA); |
1775 | out->updateFillColor(state); | 1775 | out->updateFillColor(state); |
1776 | 1776 | ||
1777 | // construct path for first circle | 1777 | // construct path for first circle |
1778 | state->moveTo(xa + ra, ya); | 1778 | state->moveTo(xa + ra, ya); |
1779 | for (k = 1; k < n; ++k) { | 1779 | for (k = 1; k < n; ++k) { |
1780 | angle = ((fouble)k / (fouble)n) * 2 * M_PI; | 1780 | angle = ((fouble)k / (fouble)n) * 2 * M_PI; |
1781 | state->lineTo(xa + ra * cos(angle), ya + ra * sin(angle)); | 1781 | state->lineTo(xa + ra * cos(angle), ya + ra * sin(angle)); |
1782 | } | 1782 | } |
1783 | state->closePath(); | 1783 | state->closePath(); |
1784 | 1784 | ||
1785 | // construct and append path for second circle | 1785 | // construct and append path for second circle |
1786 | state->moveTo(xb + rb, yb); | 1786 | state->moveTo(xb + rb, yb); |
1787 | for (k = 1; k < n; ++k) { | 1787 | for (k = 1; k < n; ++k) { |
1788 | angle = ((fouble)k / (fouble)n) * 2 * M_PI; | 1788 | angle = ((fouble)k / (fouble)n) * 2 * M_PI; |
1789 | state->lineTo(xb + rb * cos(angle), yb + rb * sin(angle)); | 1789 | state->lineTo(xb + rb * cos(angle), yb + rb * sin(angle)); |
1790 | } | 1790 | } |
1791 | state->closePath(); | 1791 | state->closePath(); |
1792 | 1792 | ||
1793 | // fill the ring | 1793 | // fill the ring |
1794 | out->eoFill(state); | 1794 | out->eoFill(state); |
1795 | state->clearPath(); | 1795 | state->clearPath(); |
1796 | 1796 | ||
1797 | // step to the next value of t | 1797 | // step to the next value of t |
1798 | ia = ib; | 1798 | ia = ib; |
1799 | sa = sb; | 1799 | sa = sb; |
1800 | ta = tb; | 1800 | ta = tb; |
1801 | xa = xb; | 1801 | xa = xb; |
1802 | ya = yb; | 1802 | ya = yb; |
1803 | ra = rb; | 1803 | ra = rb; |
1804 | colorA = colorB; | 1804 | colorA = colorB; |
1805 | } | 1805 | } |
1806 | } | 1806 | } |
1807 | 1807 | ||
1808 | void Gfx::doEndPath() { | 1808 | void Gfx::doEndPath() { |
1809 | if (state->isPath() && clip != clipNone) { | 1809 | if (state->isPath() && clip != clipNone) { |
1810 | state->clip(); | 1810 | state->clip(); |
1811 | if (clip == clipNormal) { | 1811 | if (clip == clipNormal) { |
1812 | out->clip(state); | 1812 | out->clip(state); |
1813 | } else { | 1813 | } else { |
1814 | out->eoClip(state); | 1814 | out->eoClip(state); |
1815 | } | 1815 | } |
1816 | } | 1816 | } |
1817 | clip = clipNone; | 1817 | clip = clipNone; |
1818 | state->clearPath(); | 1818 | state->clearPath(); |
1819 | } | 1819 | } |
1820 | 1820 | ||
1821 | //------------------------------------------------------------------------ | 1821 | //------------------------------------------------------------------------ |
1822 | // path clipping operators | 1822 | // path clipping operators |
1823 | //------------------------------------------------------------------------ | 1823 | //------------------------------------------------------------------------ |
1824 | 1824 | ||
1825 | void Gfx::opClip(Object args[], int numArgs) { | 1825 | void Gfx::opClip(Object args[], int numArgs) { |
1826 | clip = clipNormal; | 1826 | clip = clipNormal; |
1827 | } | 1827 | } |
1828 | 1828 | ||
1829 | void Gfx::opEOClip(Object args[], int numArgs) { | 1829 | void Gfx::opEOClip(Object args[], int numArgs) { |
1830 | clip = clipEO; | 1830 | clip = clipEO; |
1831 | } | 1831 | } |
1832 | 1832 | ||
1833 | //------------------------------------------------------------------------ | 1833 | //------------------------------------------------------------------------ |
1834 | // text object operators | 1834 | // text object operators |
1835 | //------------------------------------------------------------------------ | 1835 | //------------------------------------------------------------------------ |
1836 | 1836 | ||
1837 | void Gfx::opBeginText(Object args[], int numArgs) { | 1837 | void Gfx::opBeginText(Object args[], int numArgs) { |
1838 | state->setTextMat(1, 0, 0, 1, 0, 0); | 1838 | state->setTextMat(1, 0, 0, 1, 0, 0); |
1839 | state->textMoveTo(0, 0); | 1839 | state->textMoveTo(0, 0); |
1840 | out->updateTextMat(state); | 1840 | out->updateTextMat(state); |
1841 | out->updateTextPos(state); | 1841 | out->updateTextPos(state); |
1842 | fontChanged = gTrue; | 1842 | fontChanged = gTrue; |
1843 | } | 1843 | } |
1844 | 1844 | ||
1845 | void Gfx::opEndText(Object args[], int numArgs) { | 1845 | void Gfx::opEndText(Object args[], int numArgs) { |
1846 | } | 1846 | } |
1847 | 1847 | ||
1848 | //------------------------------------------------------------------------ | 1848 | //------------------------------------------------------------------------ |
1849 | // text state operators | 1849 | // text state operators |
1850 | //------------------------------------------------------------------------ | 1850 | //------------------------------------------------------------------------ |
1851 | 1851 | ||
1852 | void Gfx::opSetCharSpacing(Object args[], int numArgs) { | 1852 | void Gfx::opSetCharSpacing(Object args[], int numArgs) { |
1853 | state->setCharSpace(args[0].getNum()); | 1853 | state->setCharSpace(args[0].getNum()); |
1854 | out->updateCharSpace(state); | 1854 | out->updateCharSpace(state); |
1855 | } | 1855 | } |
1856 | 1856 | ||
1857 | void Gfx::opSetFont(Object args[], int numArgs) { | 1857 | void Gfx::opSetFont(Object args[], int numArgs) { |
1858 | GfxFont *font; | 1858 | GfxFont *font; |
1859 | 1859 | ||
1860 | if (!(font = res->lookupFont(args[0].getName()))) { | 1860 | if (!(font = res->lookupFont(args[0].getName()))) { |
1861 | return; | 1861 | return; |
1862 | } | 1862 | } |
1863 | if (printCommands) { | 1863 | if (printCommands) { |
1864 | printf(" font: tag=%s name='%s' %g\n", | 1864 | printf(" font: tag=%s name='%s' %g\n", |
1865 | font->getTag()->getCString(), | 1865 | font->getTag()->getCString(), |
1866 | font->getName() ? font->getName()->getCString() : "???", | 1866 | font->getName() ? font->getName()->getCString() : "???", |
1867 | args[1].getNum()); | 1867 | static_cast<double>(args[1].getNum())); |
1868 | fflush(stdout); | 1868 | fflush(stdout); |
1869 | } | 1869 | } |
1870 | state->setFont(font, args[1].getNum()); | 1870 | state->setFont(font, args[1].getNum()); |
1871 | fontChanged = gTrue; | 1871 | fontChanged = gTrue; |
1872 | } | 1872 | } |
1873 | 1873 | ||
1874 | void Gfx::opSetTextLeading(Object args[], int numArgs) { | 1874 | void Gfx::opSetTextLeading(Object args[], int numArgs) { |
1875 | state->setLeading(args[0].getNum()); | 1875 | state->setLeading(args[0].getNum()); |
1876 | } | 1876 | } |
1877 | 1877 | ||
1878 | void Gfx::opSetTextRender(Object args[], int numArgs) { | 1878 | void Gfx::opSetTextRender(Object args[], int numArgs) { |
1879 | state->setRender(args[0].getInt()); | 1879 | state->setRender(args[0].getInt()); |
1880 | out->updateRender(state); | 1880 | out->updateRender(state); |
1881 | } | 1881 | } |
1882 | 1882 | ||
1883 | void Gfx::opSetTextRise(Object args[], int numArgs) { | 1883 | void Gfx::opSetTextRise(Object args[], int numArgs) { |
1884 | state->setRise(args[0].getNum()); | 1884 | state->setRise(args[0].getNum()); |
1885 | out->updateRise(state); | 1885 | out->updateRise(state); |
1886 | } | 1886 | } |
1887 | 1887 | ||
1888 | void Gfx::opSetWordSpacing(Object args[], int numArgs) { | 1888 | void Gfx::opSetWordSpacing(Object args[], int numArgs) { |
1889 | state->setWordSpace(args[0].getNum()); | 1889 | state->setWordSpace(args[0].getNum()); |
1890 | out->updateWordSpace(state); | 1890 | out->updateWordSpace(state); |
1891 | } | 1891 | } |
1892 | 1892 | ||
1893 | void Gfx::opSetHorizScaling(Object args[], int numArgs) { | 1893 | void Gfx::opSetHorizScaling(Object args[], int numArgs) { |
1894 | state->setHorizScaling(args[0].getNum()); | 1894 | state->setHorizScaling(args[0].getNum()); |
1895 | out->updateHorizScaling(state); | 1895 | out->updateHorizScaling(state); |
1896 | fontChanged = gTrue; | 1896 | fontChanged = gTrue; |
1897 | } | 1897 | } |
1898 | 1898 | ||
1899 | //------------------------------------------------------------------------ | 1899 | //------------------------------------------------------------------------ |
1900 | // text positioning operators | 1900 | // text positioning operators |
1901 | //------------------------------------------------------------------------ | 1901 | //------------------------------------------------------------------------ |
1902 | 1902 | ||
1903 | void Gfx::opTextMove(Object args[], int numArgs) { | 1903 | void Gfx::opTextMove(Object args[], int numArgs) { |
1904 | fouble tx, ty; | 1904 | fouble tx, ty; |
1905 | 1905 | ||
1906 | tx = state->getLineX() + args[0].getNum(); | 1906 | tx = state->getLineX() + args[0].getNum(); |
1907 | ty = state->getLineY() + args[1].getNum(); | 1907 | ty = state->getLineY() + args[1].getNum(); |
1908 | state->textMoveTo(tx, ty); | 1908 | state->textMoveTo(tx, ty); |
1909 | out->updateTextPos(state); | 1909 | out->updateTextPos(state); |
1910 | } | 1910 | } |
1911 | 1911 | ||
1912 | void Gfx::opTextMoveSet(Object args[], int numArgs) { | 1912 | void Gfx::opTextMoveSet(Object args[], int numArgs) { |
1913 | fouble tx, ty; | 1913 | fouble tx, ty; |
1914 | 1914 | ||
1915 | tx = state->getLineX() + args[0].getNum(); | 1915 | tx = state->getLineX() + args[0].getNum(); |
1916 | ty = args[1].getNum(); | 1916 | ty = args[1].getNum(); |
1917 | state->setLeading(-ty); | 1917 | state->setLeading(-ty); |
1918 | ty += state->getLineY(); | 1918 | ty += state->getLineY(); |
1919 | state->textMoveTo(tx, ty); | 1919 | state->textMoveTo(tx, ty); |
1920 | out->updateTextPos(state); | 1920 | out->updateTextPos(state); |
1921 | } | 1921 | } |
1922 | 1922 | ||
1923 | void Gfx::opSetTextMatrix(Object args[], int numArgs) { | 1923 | void Gfx::opSetTextMatrix(Object args[], int numArgs) { |
1924 | state->setTextMat(args[0].getNum(), args[1].getNum(), | 1924 | state->setTextMat(args[0].getNum(), args[1].getNum(), |
1925 | args[2].getNum(), args[3].getNum(), | 1925 | args[2].getNum(), args[3].getNum(), |
1926 | args[4].getNum(), args[5].getNum()); | 1926 | args[4].getNum(), args[5].getNum()); |
1927 | state->textMoveTo(0, 0); | 1927 | state->textMoveTo(0, 0); |
1928 | out->updateTextMat(state); | 1928 | out->updateTextMat(state); |
1929 | out->updateTextPos(state); | 1929 | out->updateTextPos(state); |
1930 | fontChanged = gTrue; | 1930 | fontChanged = gTrue; |
1931 | } | 1931 | } |
1932 | 1932 | ||
1933 | void Gfx::opTextNextLine(Object args[], int numArgs) { | 1933 | void Gfx::opTextNextLine(Object args[], int numArgs) { |
1934 | fouble tx, ty; | 1934 | fouble tx, ty; |
1935 | 1935 | ||
1936 | tx = state->getLineX(); | 1936 | tx = state->getLineX(); |
1937 | ty = state->getLineY() - state->getLeading(); | 1937 | ty = state->getLineY() - state->getLeading(); |
1938 | state->textMoveTo(tx, ty); | 1938 | state->textMoveTo(tx, ty); |
1939 | out->updateTextPos(state); | 1939 | out->updateTextPos(state); |
1940 | } | 1940 | } |
1941 | 1941 | ||
1942 | //------------------------------------------------------------------------ | 1942 | //------------------------------------------------------------------------ |
1943 | // text string operators | 1943 | // text string operators |
1944 | //------------------------------------------------------------------------ | 1944 | //------------------------------------------------------------------------ |
1945 | 1945 | ||
1946 | void Gfx::opShowText(Object args[], int numArgs) { | 1946 | void Gfx::opShowText(Object args[], int numArgs) { |
1947 | if (!state->getFont()) { | 1947 | if (!state->getFont()) { |
1948 | error(getPos(), "No font in show"); | 1948 | error(getPos(), "No font in show"); |
1949 | return; | 1949 | return; |
1950 | } | 1950 | } |
1951 | doShowText(args[0].getString()); | 1951 | doShowText(args[0].getString()); |
1952 | } | 1952 | } |
1953 | 1953 | ||
1954 | void Gfx::opMoveShowText(Object args[], int numArgs) { | 1954 | void Gfx::opMoveShowText(Object args[], int numArgs) { |
1955 | fouble tx, ty; | 1955 | fouble tx, ty; |
1956 | 1956 | ||
1957 | if (!state->getFont()) { | 1957 | if (!state->getFont()) { |
1958 | error(getPos(), "No font in move/show"); | 1958 | error(getPos(), "No font in move/show"); |
1959 | return; | 1959 | return; |
1960 | } | 1960 | } |
1961 | tx = state->getLineX(); | 1961 | tx = state->getLineX(); |
1962 | ty = state->getLineY() - state->getLeading(); | 1962 | ty = state->getLineY() - state->getLeading(); |
1963 | state->textMoveTo(tx, ty); | 1963 | state->textMoveTo(tx, ty); |
1964 | out->updateTextPos(state); | 1964 | out->updateTextPos(state); |
1965 | doShowText(args[0].getString()); | 1965 | doShowText(args[0].getString()); |
1966 | } | 1966 | } |
1967 | 1967 | ||
1968 | void Gfx::opMoveSetShowText(Object args[], int numArgs) { | 1968 | void Gfx::opMoveSetShowText(Object args[], int numArgs) { |
1969 | fouble tx, ty; | 1969 | fouble tx, ty; |
1970 | 1970 | ||
1971 | if (!state->getFont()) { | 1971 | if (!state->getFont()) { |
1972 | error(getPos(), "No font in move/set/show"); | 1972 | error(getPos(), "No font in move/set/show"); |
1973 | return; | 1973 | return; |
1974 | } | 1974 | } |
1975 | state->setWordSpace(args[0].getNum()); | 1975 | state->setWordSpace(args[0].getNum()); |
1976 | state->setCharSpace(args[1].getNum()); | 1976 | state->setCharSpace(args[1].getNum()); |
1977 | tx = state->getLineX(); | 1977 | tx = state->getLineX(); |
1978 | ty = state->getLineY() - state->getLeading(); | 1978 | ty = state->getLineY() - state->getLeading(); |
1979 | state->textMoveTo(tx, ty); | 1979 | state->textMoveTo(tx, ty); |
1980 | out->updateWordSpace(state); | 1980 | out->updateWordSpace(state); |
1981 | out->updateCharSpace(state); | 1981 | out->updateCharSpace(state); |
1982 | out->updateTextPos(state); | 1982 | out->updateTextPos(state); |
1983 | doShowText(args[2].getString()); | 1983 | doShowText(args[2].getString()); |
1984 | } | 1984 | } |
1985 | 1985 | ||
1986 | void Gfx::opShowSpaceText(Object args[], int numArgs) { | 1986 | void Gfx::opShowSpaceText(Object args[], int numArgs) { |
1987 | Array *a; | 1987 | Array *a; |
1988 | Object obj; | 1988 | Object obj; |
1989 | int wMode; | 1989 | int wMode; |
1990 | int i; | 1990 | int i; |
1991 | 1991 | ||
1992 | if (!state->getFont()) { | 1992 | if (!state->getFont()) { |
1993 | error(getPos(), "No font in show/space"); | 1993 | error(getPos(), "No font in show/space"); |
1994 | return; | 1994 | return; |
1995 | } | 1995 | } |
1996 | wMode = state->getFont()->getWMode(); | 1996 | wMode = state->getFont()->getWMode(); |
1997 | a = args[0].getArray(); | 1997 | a = args[0].getArray(); |
1998 | for (i = 0; i < a->getLength(); ++i) { | 1998 | for (i = 0; i < a->getLength(); ++i) { |
1999 | a->get(i, &obj); | 1999 | a->get(i, &obj); |
2000 | if (obj.isNum()) { | 2000 | if (obj.isNum()) { |
2001 | if (wMode) { | 2001 | if (wMode) { |
2002 | state->textShift(0, -obj.getNum() * 0.001 * state->getFontSize()); | 2002 | state->textShift(0, -obj.getNum() * 0.001 * state->getFontSize()); |
2003 | } else { | 2003 | } else { |
2004 | state->textShift(-obj.getNum() * 0.001 * state->getFontSize(), 0); | 2004 | state->textShift(-obj.getNum() * 0.001 * state->getFontSize(), 0); |
2005 | } | 2005 | } |
2006 | out->updateTextShift(state, obj.getNum()); | 2006 | out->updateTextShift(state, obj.getNum()); |
2007 | } else if (obj.isString()) { | 2007 | } else if (obj.isString()) { |
2008 | doShowText(obj.getString()); | 2008 | doShowText(obj.getString()); |
2009 | } else { | 2009 | } else { |
2010 | error(getPos(), "Element of show/space array must be number or string"); | 2010 | error(getPos(), "Element of show/space array must be number or string"); |
2011 | } | 2011 | } |
2012 | obj.free(); | 2012 | obj.free(); |
2013 | } | 2013 | } |
2014 | } | 2014 | } |
2015 | 2015 | ||
2016 | void Gfx::doShowText(GString *s) { | 2016 | void Gfx::doShowText(GString *s) { |
2017 | GfxFont *font; | 2017 | GfxFont *font; |
2018 | int wMode; | 2018 | int wMode; |
2019 | fouble riseX, riseY; | 2019 | fouble riseX, riseY; |
2020 | CharCode code; | 2020 | CharCode code; |
2021 | Unicode u[8]; | 2021 | Unicode u[8]; |
2022 | fouble x, y, dx, dy, dx2, dy2, curX, curY, tdx, tdy; | 2022 | fouble x, y, dx, dy, dx2, dy2, curX, curY, tdx, tdy; |
2023 | fouble originX, originY, tOriginX, tOriginY; | 2023 | fouble originX, originY, tOriginX, tOriginY; |
2024 | fouble oldCTM[6], newCTM[6]; | 2024 | fouble oldCTM[6], newCTM[6]; |
2025 | fouble *mat; | 2025 | fouble *mat; |
2026 | Object charProc; | 2026 | Object charProc; |
2027 | Dict *resDict; | 2027 | Dict *resDict; |
2028 | Parser *oldParser; | 2028 | Parser *oldParser; |
2029 | char *p; | 2029 | char *p; |
2030 | int len, n, uLen, nChars, nSpaces, i; | 2030 | int len, n, uLen, nChars, nSpaces, i; |
2031 | 2031 | ||
2032 | if (fontChanged) { | 2032 | if (fontChanged) { |
2033 | out->updateFont(state); | 2033 | out->updateFont(state); |
2034 | fontChanged = gFalse; | 2034 | fontChanged = gFalse; |
2035 | } | 2035 | } |
2036 | font = state->getFont(); | 2036 | font = state->getFont(); |
2037 | wMode = font->getWMode(); | 2037 | wMode = font->getWMode(); |
2038 | 2038 | ||
2039 | if (out->useDrawChar()) { | 2039 | if (out->useDrawChar()) { |
2040 | out->beginString(state, s); | 2040 | out->beginString(state, s); |
2041 | } | 2041 | } |
2042 | 2042 | ||
2043 | // handle a Type 3 char | 2043 | // handle a Type 3 char |
2044 | if (font->getType() == fontType3 && out->interpretType3Chars()) { | 2044 | if (font->getType() == fontType3 && out->interpretType3Chars()) { |
2045 | mat = state->getCTM(); | 2045 | mat = state->getCTM(); |
2046 | for (i = 0; i < 6; ++i) { | 2046 | for (i = 0; i < 6; ++i) { |
2047 | oldCTM[i] = mat[i]; | 2047 | oldCTM[i] = mat[i]; |
2048 | } | 2048 | } |
2049 | mat = state->getTextMat(); | 2049 | mat = state->getTextMat(); |
2050 | newCTM[0] = mat[0] * oldCTM[0] + mat[1] * oldCTM[2]; | 2050 | newCTM[0] = mat[0] * oldCTM[0] + mat[1] * oldCTM[2]; |
2051 | newCTM[1] = mat[0] * oldCTM[1] + mat[1] * oldCTM[3]; | 2051 | newCTM[1] = mat[0] * oldCTM[1] + mat[1] * oldCTM[3]; |
2052 | newCTM[2] = mat[2] * oldCTM[0] + mat[3] * oldCTM[2]; | 2052 | newCTM[2] = mat[2] * oldCTM[0] + mat[3] * oldCTM[2]; |
2053 | newCTM[3] = mat[2] * oldCTM[1] + mat[3] * oldCTM[3]; | 2053 | newCTM[3] = mat[2] * oldCTM[1] + mat[3] * oldCTM[3]; |
2054 | mat = font->getFontMatrix(); | 2054 | mat = font->getFontMatrix(); |
2055 | newCTM[0] = mat[0] * newCTM[0] + mat[1] * newCTM[2]; | 2055 | newCTM[0] = mat[0] * newCTM[0] + mat[1] * newCTM[2]; |
2056 | newCTM[1] = mat[0] * newCTM[1] + mat[1] * newCTM[3]; | 2056 | newCTM[1] = mat[0] * newCTM[1] + mat[1] * newCTM[3]; |
2057 | newCTM[2] = mat[2] * newCTM[0] + mat[3] * newCTM[2]; | 2057 | newCTM[2] = mat[2] * newCTM[0] + mat[3] * newCTM[2]; |
2058 | newCTM[3] = mat[2] * newCTM[1] + mat[3] * newCTM[3]; | 2058 | newCTM[3] = mat[2] * newCTM[1] + mat[3] * newCTM[3]; |
2059 | newCTM[0] *= state->getFontSize(); | 2059 | newCTM[0] *= state->getFontSize(); |
diff --git a/noncore/unsupported/qpdf/xpdf/Object.cc b/noncore/unsupported/qpdf/xpdf/Object.cc index 6d92c6a..77f1317 100644 --- a/noncore/unsupported/qpdf/xpdf/Object.cc +++ b/noncore/unsupported/qpdf/xpdf/Object.cc | |||
@@ -1,223 +1,223 @@ | |||
1 | //======================================================================== | 1 | //======================================================================== |
2 | // | 2 | // |
3 | // Object.cc | 3 | // Object.cc |
4 | // | 4 | // |
5 | // Copyright 1996-2002 Glyph & Cog, LLC | 5 | // Copyright 1996-2002 Glyph & Cog, LLC |
6 | // | 6 | // |
7 | //======================================================================== | 7 | //======================================================================== |
8 | 8 | ||
9 | #ifdef __GNUC__ | 9 | #ifdef __GNUC__ |
10 | #pragma implementation | 10 | #pragma implementation |
11 | #endif | 11 | #endif |
12 | 12 | ||
13 | #include <aconf.h> | 13 | #include <aconf.h> |
14 | #include <stddef.h> | 14 | #include <stddef.h> |
15 | #include "Object.h" | 15 | #include "Object.h" |
16 | #include "Array.h" | 16 | #include "Array.h" |
17 | #include "Dict.h" | 17 | #include "Dict.h" |
18 | #include "Error.h" | 18 | #include "Error.h" |
19 | #include "Stream.h" | 19 | #include "Stream.h" |
20 | #include "XRef.h" | 20 | #include "XRef.h" |
21 | 21 | ||
22 | //------------------------------------------------------------------------ | 22 | //------------------------------------------------------------------------ |
23 | // Object | 23 | // Object |
24 | //------------------------------------------------------------------------ | 24 | //------------------------------------------------------------------------ |
25 | 25 | ||
26 | char *objTypeNames[numObjTypes] = { | 26 | char *objTypeNames[numObjTypes] = { |
27 | "boolean", | 27 | "boolean", |
28 | "integer", | 28 | "integer", |
29 | "real", | 29 | "real", |
30 | "string", | 30 | "string", |
31 | "name", | 31 | "name", |
32 | "null", | 32 | "null", |
33 | "array", | 33 | "array", |
34 | "dictionary", | 34 | "dictionary", |
35 | "stream", | 35 | "stream", |
36 | "ref", | 36 | "ref", |
37 | "cmd", | 37 | "cmd", |
38 | "error", | 38 | "error", |
39 | "eof", | 39 | "eof", |
40 | "none" | 40 | "none" |
41 | }; | 41 | }; |
42 | 42 | ||
43 | #ifdef DEBUG_MEM | 43 | #ifdef DEBUG_MEM |
44 | int Object::numAlloc[numObjTypes] = | 44 | int Object::numAlloc[numObjTypes] = |
45 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; | 45 | {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
46 | #endif | 46 | #endif |
47 | 47 | ||
48 | Object *Object::initArray(XRef *xref) { | 48 | Object *Object::initArray(XRef *xref) { |
49 | initObj(objArray); | 49 | initObj(objArray); |
50 | array = new Array(xref); | 50 | array = new Array(xref); |
51 | return this; | 51 | return this; |
52 | } | 52 | } |
53 | 53 | ||
54 | Object *Object::initDict(XRef *xref) { | 54 | Object *Object::initDict(XRef *xref) { |
55 | initObj(objDict); | 55 | initObj(objDict); |
56 | dict = new Dict(xref); | 56 | dict = new Dict(xref); |
57 | return this; | 57 | return this; |
58 | } | 58 | } |
59 | 59 | ||
60 | Object *Object::initStream(Stream *streamA) { | 60 | Object *Object::initStream(Stream *streamA) { |
61 | initObj(objStream); | 61 | initObj(objStream); |
62 | stream = streamA; | 62 | stream = streamA; |
63 | return this; | 63 | return this; |
64 | } | 64 | } |
65 | 65 | ||
66 | Object *Object::copy(Object *obj) { | 66 | Object *Object::copy(Object *obj) { |
67 | *obj = *this; | 67 | *obj = *this; |
68 | switch (type) { | 68 | switch (type) { |
69 | case objString: | 69 | case objString: |
70 | obj->string = string->copy(); | 70 | obj->string = string->copy(); |
71 | break; | 71 | break; |
72 | case objName: | 72 | case objName: |
73 | obj->name = copyString(name); | 73 | obj->name = copyString(name); |
74 | break; | 74 | break; |
75 | case objArray: | 75 | case objArray: |
76 | array->incRef(); | 76 | array->incRef(); |
77 | break; | 77 | break; |
78 | case objDict: | 78 | case objDict: |
79 | dict->incRef(); | 79 | dict->incRef(); |
80 | break; | 80 | break; |
81 | case objStream: | 81 | case objStream: |
82 | stream->incRef(); | 82 | stream->incRef(); |
83 | break; | 83 | break; |
84 | case objCmd: | 84 | case objCmd: |
85 | obj->cmd = copyString(cmd); | 85 | obj->cmd = copyString(cmd); |
86 | break; | 86 | break; |
87 | default: | 87 | default: |
88 | break; | 88 | break; |
89 | } | 89 | } |
90 | #ifdef DEBUG_MEM | 90 | #ifdef DEBUG_MEM |
91 | ++numAlloc[type]; | 91 | ++numAlloc[type]; |
92 | #endif | 92 | #endif |
93 | return obj; | 93 | return obj; |
94 | } | 94 | } |
95 | 95 | ||
96 | Object *Object::fetch(XRef *xref, Object *obj) { | 96 | Object *Object::fetch(XRef *xref, Object *obj) { |
97 | return (type == objRef && xref) ? | 97 | return (type == objRef && xref) ? |
98 | xref->fetch(ref.num, ref.gen, obj) : copy(obj); | 98 | xref->fetch(ref.num, ref.gen, obj) : copy(obj); |
99 | } | 99 | } |
100 | 100 | ||
101 | void Object::free() { | 101 | void Object::free() { |
102 | switch (type) { | 102 | switch (type) { |
103 | case objString: | 103 | case objString: |
104 | delete string; | 104 | delete string; |
105 | break; | 105 | break; |
106 | case objName: | 106 | case objName: |
107 | gfree(name); | 107 | gfree(name); |
108 | break; | 108 | break; |
109 | case objArray: | 109 | case objArray: |
110 | if (!array->decRef()) { | 110 | if (!array->decRef()) { |
111 | delete array; | 111 | delete array; |
112 | } | 112 | } |
113 | break; | 113 | break; |
114 | case objDict: | 114 | case objDict: |
115 | if (!dict->decRef()) { | 115 | if (!dict->decRef()) { |
116 | delete dict; | 116 | delete dict; |
117 | } | 117 | } |
118 | break; | 118 | break; |
119 | case objStream: | 119 | case objStream: |
120 | if (!stream->decRef()) { | 120 | if (!stream->decRef()) { |
121 | delete stream; | 121 | delete stream; |
122 | } | 122 | } |
123 | break; | 123 | break; |
124 | case objCmd: | 124 | case objCmd: |
125 | gfree(cmd); | 125 | gfree(cmd); |
126 | break; | 126 | break; |
127 | default: | 127 | default: |
128 | break; | 128 | break; |
129 | } | 129 | } |
130 | #ifdef DEBUG_MEM | 130 | #ifdef DEBUG_MEM |
131 | --numAlloc[type]; | 131 | --numAlloc[type]; |
132 | #endif | 132 | #endif |
133 | type = objNone; | 133 | type = objNone; |
134 | } | 134 | } |
135 | 135 | ||
136 | char *Object::getTypeName() { | 136 | char *Object::getTypeName() { |
137 | return objTypeNames[type]; | 137 | return objTypeNames[type]; |
138 | } | 138 | } |
139 | 139 | ||
140 | void Object::print(FILE *f) { | 140 | void Object::print(FILE *f) { |
141 | Object obj; | 141 | Object obj; |
142 | int i; | 142 | int i; |
143 | 143 | ||
144 | switch (type) { | 144 | switch (type) { |
145 | case objBool: | 145 | case objBool: |
146 | fprintf(f, "%s", booln ? "true" : "false"); | 146 | fprintf(f, "%s", booln ? "true" : "false"); |
147 | break; | 147 | break; |
148 | case objInt: | 148 | case objInt: |
149 | fprintf(f, "%d", intg); | 149 | fprintf(f, "%d", intg); |
150 | break; | 150 | break; |
151 | case objReal: | 151 | case objReal: |
152 | fprintf(f, "%g", real); | 152 | fprintf(f, "%g", static_cast<double>(real)); |
153 | break; | 153 | break; |
154 | case objString: | 154 | case objString: |
155 | fprintf(f, "("); | 155 | fprintf(f, "("); |
156 | fwrite(string->getCString(), 1, string->getLength(), stdout); | 156 | fwrite(string->getCString(), 1, string->getLength(), stdout); |
157 | fprintf(f, ")"); | 157 | fprintf(f, ")"); |
158 | break; | 158 | break; |
159 | case objName: | 159 | case objName: |
160 | fprintf(f, "/%s", name); | 160 | fprintf(f, "/%s", name); |
161 | break; | 161 | break; |
162 | case objNull: | 162 | case objNull: |
163 | fprintf(f, "null"); | 163 | fprintf(f, "null"); |
164 | break; | 164 | break; |
165 | case objArray: | 165 | case objArray: |
166 | fprintf(f, "["); | 166 | fprintf(f, "["); |
167 | for (i = 0; i < arrayGetLength(); ++i) { | 167 | for (i = 0; i < arrayGetLength(); ++i) { |
168 | if (i > 0) | 168 | if (i > 0) |
169 | fprintf(f, " "); | 169 | fprintf(f, " "); |
170 | arrayGetNF(i, &obj); | 170 | arrayGetNF(i, &obj); |
171 | obj.print(f); | 171 | obj.print(f); |
172 | obj.free(); | 172 | obj.free(); |
173 | } | 173 | } |
174 | fprintf(f, "]"); | 174 | fprintf(f, "]"); |
175 | break; | 175 | break; |
176 | case objDict: | 176 | case objDict: |
177 | fprintf(f, "<<"); | 177 | fprintf(f, "<<"); |
178 | for (i = 0; i < dictGetLength(); ++i) { | 178 | for (i = 0; i < dictGetLength(); ++i) { |
179 | fprintf(f, " /%s ", dictGetKey(i)); | 179 | fprintf(f, " /%s ", dictGetKey(i)); |
180 | dictGetValNF(i, &obj); | 180 | dictGetValNF(i, &obj); |
181 | obj.print(f); | 181 | obj.print(f); |
182 | obj.free(); | 182 | obj.free(); |
183 | } | 183 | } |
184 | fprintf(f, " >>"); | 184 | fprintf(f, " >>"); |
185 | break; | 185 | break; |
186 | case objStream: | 186 | case objStream: |
187 | fprintf(f, "<stream>"); | 187 | fprintf(f, "<stream>"); |
188 | break; | 188 | break; |
189 | case objRef: | 189 | case objRef: |
190 | fprintf(f, "%d %d R", ref.num, ref.gen); | 190 | fprintf(f, "%d %d R", ref.num, ref.gen); |
191 | break; | 191 | break; |
192 | case objCmd: | 192 | case objCmd: |
193 | fprintf(f, "%s", cmd); | 193 | fprintf(f, "%s", cmd); |
194 | break; | 194 | break; |
195 | case objError: | 195 | case objError: |
196 | fprintf(f, "<error>"); | 196 | fprintf(f, "<error>"); |
197 | break; | 197 | break; |
198 | case objEOF: | 198 | case objEOF: |
199 | fprintf(f, "<EOF>"); | 199 | fprintf(f, "<EOF>"); |
200 | break; | 200 | break; |
201 | case objNone: | 201 | case objNone: |
202 | fprintf(f, "<none>"); | 202 | fprintf(f, "<none>"); |
203 | break; | 203 | break; |
204 | } | 204 | } |
205 | } | 205 | } |
206 | 206 | ||
207 | void Object::memCheck(FILE *f) { | 207 | void Object::memCheck(FILE *f) { |
208 | #ifdef DEBUG_MEM | 208 | #ifdef DEBUG_MEM |
209 | int i; | 209 | int i; |
210 | int t; | 210 | int t; |
211 | 211 | ||
212 | t = 0; | 212 | t = 0; |
213 | for (i = 0; i < numObjTypes; ++i) | 213 | for (i = 0; i < numObjTypes; ++i) |
214 | t += numAlloc[i]; | 214 | t += numAlloc[i]; |
215 | if (t > 0) { | 215 | if (t > 0) { |
216 | fprintf(f, "Allocated objects:\n"); | 216 | fprintf(f, "Allocated objects:\n"); |
217 | for (i = 0; i < numObjTypes; ++i) { | 217 | for (i = 0; i < numObjTypes; ++i) { |
218 | if (numAlloc[i] > 0) | 218 | if (numAlloc[i] > 0) |
219 | fprintf(f, " %-20s: %6d\n", objTypeNames[i], numAlloc[i]); | 219 | fprintf(f, " %-20s: %6d\n", objTypeNames[i], numAlloc[i]); |
220 | } | 220 | } |
221 | } | 221 | } |
222 | #endif | 222 | #endif |
223 | } | 223 | } |
diff --git a/noncore/unsupported/qpdf/xpdf/Page.cc b/noncore/unsupported/qpdf/xpdf/Page.cc index 9cc08c4..aead7da 100644 --- a/noncore/unsupported/qpdf/xpdf/Page.cc +++ b/noncore/unsupported/qpdf/xpdf/Page.cc | |||
@@ -41,241 +41,241 @@ PageAttrs::PageAttrs(PageAttrs *attrs, Dict *dict) { | |||
41 | rotate = attrs->rotate; | 41 | rotate = attrs->rotate; |
42 | attrs->resources.copy(&resources); | 42 | attrs->resources.copy(&resources); |
43 | } else { | 43 | } else { |
44 | // set default MediaBox to 8.5" x 11" -- this shouldn't be necessary | 44 | // set default MediaBox to 8.5" x 11" -- this shouldn't be necessary |
45 | // but some (non-compliant) PDF files don't specify a MediaBox | 45 | // but some (non-compliant) PDF files don't specify a MediaBox |
46 | mediaBox.x1 = 0; | 46 | mediaBox.x1 = 0; |
47 | mediaBox.y1 = 0; | 47 | mediaBox.y1 = 0; |
48 | mediaBox.x2 = 612; | 48 | mediaBox.x2 = 612; |
49 | mediaBox.y2 = 792; | 49 | mediaBox.y2 = 792; |
50 | cropBox.x1 = cropBox.y1 = cropBox.x2 = cropBox.y2 = 0; | 50 | cropBox.x1 = cropBox.y1 = cropBox.x2 = cropBox.y2 = 0; |
51 | haveCropBox = gFalse; | 51 | haveCropBox = gFalse; |
52 | rotate = 0; | 52 | rotate = 0; |
53 | resources.initNull(); | 53 | resources.initNull(); |
54 | } | 54 | } |
55 | 55 | ||
56 | // media box | 56 | // media box |
57 | readBox(dict, "MediaBox", &mediaBox); | 57 | readBox(dict, "MediaBox", &mediaBox); |
58 | 58 | ||
59 | // crop box | 59 | // crop box |
60 | cropBox = mediaBox; | 60 | cropBox = mediaBox; |
61 | haveCropBox = readBox(dict, "CropBox", &cropBox); | 61 | haveCropBox = readBox(dict, "CropBox", &cropBox); |
62 | 62 | ||
63 | // if the MediaBox is excessively larger than the CropBox, | 63 | // if the MediaBox is excessively larger than the CropBox, |
64 | // just use the CropBox | 64 | // just use the CropBox |
65 | limitToCropBox = gFalse; | 65 | limitToCropBox = gFalse; |
66 | if (haveCropBox) { | 66 | if (haveCropBox) { |
67 | w = 0.25 * (cropBox.x2 - cropBox.x1); | 67 | w = 0.25 * (cropBox.x2 - cropBox.x1); |
68 | h = 0.25 * (cropBox.y2 - cropBox.y1); | 68 | h = 0.25 * (cropBox.y2 - cropBox.y1); |
69 | if ((cropBox.x1 - mediaBox.x1) + (mediaBox.x2 - cropBox.x2) > w || | 69 | if ((cropBox.x1 - mediaBox.x1) + (mediaBox.x2 - cropBox.x2) > w || |
70 | (cropBox.y1 - mediaBox.y1) + (mediaBox.y2 - cropBox.y2) > h) { | 70 | (cropBox.y1 - mediaBox.y1) + (mediaBox.y2 - cropBox.y2) > h) { |
71 | limitToCropBox = gTrue; | 71 | limitToCropBox = gTrue; |
72 | } | 72 | } |
73 | } | 73 | } |
74 | 74 | ||
75 | // other boxes | 75 | // other boxes |
76 | bleedBox = cropBox; | 76 | bleedBox = cropBox; |
77 | readBox(dict, "BleedBox", &bleedBox); | 77 | readBox(dict, "BleedBox", &bleedBox); |
78 | trimBox = cropBox; | 78 | trimBox = cropBox; |
79 | readBox(dict, "TrimBox", &trimBox); | 79 | readBox(dict, "TrimBox", &trimBox); |
80 | artBox = cropBox; | 80 | artBox = cropBox; |
81 | readBox(dict, "ArtBox", &artBox); | 81 | readBox(dict, "ArtBox", &artBox); |
82 | 82 | ||
83 | // rotate | 83 | // rotate |
84 | dict->lookup("Rotate", &obj1); | 84 | dict->lookup("Rotate", &obj1); |
85 | if (obj1.isInt()) { | 85 | if (obj1.isInt()) { |
86 | rotate = obj1.getInt(); | 86 | rotate = obj1.getInt(); |
87 | } | 87 | } |
88 | obj1.free(); | 88 | obj1.free(); |
89 | while (rotate < 0) { | 89 | while (rotate < 0) { |
90 | rotate += 360; | 90 | rotate += 360; |
91 | } | 91 | } |
92 | while (rotate >= 360) { | 92 | while (rotate >= 360) { |
93 | rotate -= 360; | 93 | rotate -= 360; |
94 | } | 94 | } |
95 | 95 | ||
96 | // misc attributes | 96 | // misc attributes |
97 | dict->lookup("LastModified", &lastModified); | 97 | dict->lookup("LastModified", &lastModified); |
98 | dict->lookup("BoxColorInfo", &boxColorInfo); | 98 | dict->lookup("BoxColorInfo", &boxColorInfo); |
99 | dict->lookup("Group", &group); | 99 | dict->lookup("Group", &group); |
100 | dict->lookup("Metadata", &metadata); | 100 | dict->lookup("Metadata", &metadata); |
101 | dict->lookup("PieceInfo", &pieceInfo); | 101 | dict->lookup("PieceInfo", &pieceInfo); |
102 | dict->lookup("SeparationInfo", &separationInfo); | 102 | dict->lookup("SeparationInfo", &separationInfo); |
103 | 103 | ||
104 | // resource dictionary | 104 | // resource dictionary |
105 | dict->lookup("Resources", &obj1); | 105 | dict->lookup("Resources", &obj1); |
106 | if (obj1.isDict()) { | 106 | if (obj1.isDict()) { |
107 | resources.free(); | 107 | resources.free(); |
108 | obj1.copy(&resources); | 108 | obj1.copy(&resources); |
109 | } | 109 | } |
110 | obj1.free(); | 110 | obj1.free(); |
111 | } | 111 | } |
112 | 112 | ||
113 | PageAttrs::~PageAttrs() { | 113 | PageAttrs::~PageAttrs() { |
114 | lastModified.free(); | 114 | lastModified.free(); |
115 | boxColorInfo.free(); | 115 | boxColorInfo.free(); |
116 | group.free(); | 116 | group.free(); |
117 | metadata.free(); | 117 | metadata.free(); |
118 | pieceInfo.free(); | 118 | pieceInfo.free(); |
119 | separationInfo.free(); | 119 | separationInfo.free(); |
120 | resources.free(); | 120 | resources.free(); |
121 | } | 121 | } |
122 | 122 | ||
123 | GBool PageAttrs::readBox(Dict *dict, char *key, PDFRectangle *box) { | 123 | GBool PageAttrs::readBox(Dict *dict, char *key, PDFRectangle *box) { |
124 | PDFRectangle tmp; | 124 | PDFRectangle tmp; |
125 | Object obj1, obj2; | 125 | Object obj1, obj2; |
126 | GBool ok; | 126 | GBool ok; |
127 | 127 | ||
128 | dict->lookup(key, &obj1); | 128 | dict->lookup(key, &obj1); |
129 | if (obj1.isArray() && obj1.arrayGetLength() == 4) { | 129 | if (obj1.isArray() && obj1.arrayGetLength() == 4) { |
130 | ok = gTrue; | 130 | ok = gTrue; |
131 | obj1.arrayGet(0, &obj2); | 131 | obj1.arrayGet(0, &obj2); |
132 | if (obj2.isNum()) { | 132 | if (obj2.isNum()) { |
133 | tmp.x1 = obj2.getNum(); | 133 | tmp.x1 = obj2.getNum(); |
134 | } else { | 134 | } else { |
135 | ok = gFalse; | 135 | ok = gFalse; |
136 | } | 136 | } |
137 | obj2.free(); | 137 | obj2.free(); |
138 | obj1.arrayGet(1, &obj2); | 138 | obj1.arrayGet(1, &obj2); |
139 | if (obj2.isNum()) { | 139 | if (obj2.isNum()) { |
140 | tmp.y1 = obj2.getNum(); | 140 | tmp.y1 = obj2.getNum(); |
141 | } else { | 141 | } else { |
142 | ok = gFalse; | 142 | ok = gFalse; |
143 | } | 143 | } |
144 | obj2.free(); | 144 | obj2.free(); |
145 | obj1.arrayGet(2, &obj2); | 145 | obj1.arrayGet(2, &obj2); |
146 | if (obj2.isNum()) { | 146 | if (obj2.isNum()) { |
147 | tmp.x2 = obj2.getNum(); | 147 | tmp.x2 = obj2.getNum(); |
148 | } else { | 148 | } else { |
149 | ok = gFalse; | 149 | ok = gFalse; |
150 | } | 150 | } |
151 | obj2.free(); | 151 | obj2.free(); |
152 | obj1.arrayGet(3, &obj2); | 152 | obj1.arrayGet(3, &obj2); |
153 | if (obj2.isNum()) { | 153 | if (obj2.isNum()) { |
154 | tmp.y2 = obj2.getNum(); | 154 | tmp.y2 = obj2.getNum(); |
155 | } else { | 155 | } else { |
156 | ok = gFalse; | 156 | ok = gFalse; |
157 | } | 157 | } |
158 | obj2.free(); | 158 | obj2.free(); |
159 | if (ok) { | 159 | if (ok) { |
160 | *box = tmp; | 160 | *box = tmp; |
161 | } | 161 | } |
162 | } else { | 162 | } else { |
163 | ok = gFalse; | 163 | ok = gFalse; |
164 | } | 164 | } |
165 | obj1.free(); | 165 | obj1.free(); |
166 | return ok; | 166 | return ok; |
167 | } | 167 | } |
168 | 168 | ||
169 | //------------------------------------------------------------------------ | 169 | //------------------------------------------------------------------------ |
170 | // Page | 170 | // Page |
171 | //------------------------------------------------------------------------ | 171 | //------------------------------------------------------------------------ |
172 | 172 | ||
173 | Page::Page(XRef *xrefA, int numA, Dict *pageDict, PageAttrs *attrsA, | 173 | Page::Page(XRef *xrefA, int numA, Dict *pageDict, PageAttrs *attrsA, |
174 | GBool printCommandsA) { | 174 | GBool printCommandsA) { |
175 | 175 | ||
176 | ok = gTrue; | 176 | ok = gTrue; |
177 | xref = xrefA; | 177 | xref = xrefA; |
178 | num = numA; | 178 | num = numA; |
179 | printCommands = printCommandsA; | 179 | printCommands = printCommandsA; |
180 | 180 | ||
181 | // get attributes | 181 | // get attributes |
182 | attrs = attrsA; | 182 | attrs = attrsA; |
183 | 183 | ||
184 | // annotations | 184 | // annotations |
185 | pageDict->lookupNF("Annots", &annots); | 185 | pageDict->lookupNF("Annots", &annots); |
186 | if (!(annots.isRef() || annots.isArray() || annots.isNull())) { | 186 | if (!(annots.isRef() || annots.isArray() || annots.isNull())) { |
187 | error(-1, "Page annotations object (page %d) is wrong type (%s)", | 187 | error(-1, "Page annotations object (page %d) is wrong type (%s)", |
188 | num, annots.getTypeName()); | 188 | num, annots.getTypeName()); |
189 | annots.free(); | 189 | annots.free(); |
190 | goto err2; | 190 | goto err2; |
191 | } | 191 | } |
192 | 192 | ||
193 | // contents | 193 | // contents |
194 | pageDict->lookupNF("Contents", &contents); | 194 | pageDict->lookupNF("Contents", &contents); |
195 | if (!(contents.isRef() || contents.isArray() || | 195 | if (!(contents.isRef() || contents.isArray() || |
196 | contents.isNull())) { | 196 | contents.isNull())) { |
197 | error(-1, "Page contents object (page %d) is wrong type (%s)", | 197 | error(-1, "Page contents object (page %d) is wrong type (%s)", |
198 | num, contents.getTypeName()); | 198 | num, contents.getTypeName()); |
199 | contents.free(); | 199 | contents.free(); |
200 | goto err1; | 200 | goto err1; |
201 | } | 201 | } |
202 | 202 | ||
203 | return; | 203 | return; |
204 | 204 | ||
205 | err2: | 205 | err2: |
206 | annots.initNull(); | 206 | annots.initNull(); |
207 | err1: | 207 | err1: |
208 | contents.initNull(); | 208 | contents.initNull(); |
209 | ok = gFalse; | 209 | ok = gFalse; |
210 | } | 210 | } |
211 | 211 | ||
212 | Page::~Page() { | 212 | Page::~Page() { |
213 | delete attrs; | 213 | delete attrs; |
214 | annots.free(); | 214 | annots.free(); |
215 | contents.free(); | 215 | contents.free(); |
216 | } | 216 | } |
217 | 217 | ||
218 | void Page::display(OutputDev *out, fouble dpi, int rotate, | 218 | void Page::display(OutputDev *out, fouble dpi, int rotate, |
219 | Links *links, Catalog *catalog) { | 219 | Links *links, Catalog *catalog) { |
220 | #ifndef PDF_PARSER_ONLY | 220 | #ifndef PDF_PARSER_ONLY |
221 | PDFRectangle *box, *cropBox; | 221 | PDFRectangle *box, *cropBox; |
222 | Gfx *gfx; | 222 | Gfx *gfx; |
223 | Object obj; | 223 | Object obj; |
224 | Link *link; | 224 | Link *link; |
225 | int i; | 225 | int i; |
226 | Annots *annotList; | 226 | Annots *annotList; |
227 | 227 | ||
228 | box = getBox(); | 228 | box = getBox(); |
229 | cropBox = getCropBox(); | 229 | cropBox = getCropBox(); |
230 | 230 | ||
231 | if (printCommands) { | 231 | if (printCommands) { |
232 | printf("***** MediaBox = ll:%g,%g ur:%g,%g\n", | 232 | printf("***** MediaBox = ll:%g,%g ur:%g,%g\n", |
233 | box->x1, box->y1, box->x2, box->y2); | 233 | static_cast<double>(box->x1), static_cast<double>(box->y1), static_cast<double>(box->x2), static_cast<double>(box->y2)); |
234 | if (isCropped()) { | 234 | if (isCropped()) { |
235 | printf("***** CropBox = ll:%g,%g ur:%g,%g\n", | 235 | printf("***** CropBox = ll:%g,%g ur:%g,%g\n", |
236 | cropBox->x1, cropBox->y1, cropBox->x2, cropBox->y2); | 236 | static_cast<double>(cropBox->x1), static_cast<double>(cropBox->y1), static_cast<double>(cropBox->x2), static_cast<double>(cropBox->y2)); |
237 | } | 237 | } |
238 | printf("***** Rotate = %d\n", attrs->getRotate()); | 238 | printf("***** Rotate = %d\n", attrs->getRotate()); |
239 | } | 239 | } |
240 | 240 | ||
241 | rotate += getRotate(); | 241 | rotate += getRotate(); |
242 | if (rotate >= 360) { | 242 | if (rotate >= 360) { |
243 | rotate -= 360; | 243 | rotate -= 360; |
244 | } else if (rotate < 0) { | 244 | } else if (rotate < 0) { |
245 | rotate += 360; | 245 | rotate += 360; |
246 | } | 246 | } |
247 | gfx = new Gfx(xref, out, num, attrs->getResourceDict(), | 247 | gfx = new Gfx(xref, out, num, attrs->getResourceDict(), |
248 | dpi, box, isCropped(), cropBox, rotate, printCommands); | 248 | dpi, box, isCropped(), cropBox, rotate, printCommands); |
249 | contents.fetch(xref, &obj); | 249 | contents.fetch(xref, &obj); |
250 | if (!obj.isNull()) { | 250 | if (!obj.isNull()) { |
251 | gfx->display(&obj); | 251 | gfx->display(&obj); |
252 | } | 252 | } |
253 | obj.free(); | 253 | obj.free(); |
254 | 254 | ||
255 | // draw links | 255 | // draw links |
256 | if (links) { | 256 | if (links) { |
257 | for (i = 0; i < links->getNumLinks(); ++i) { | 257 | for (i = 0; i < links->getNumLinks(); ++i) { |
258 | link = links->getLink(i); | 258 | link = links->getLink(i); |
259 | out->drawLink(link, catalog); | 259 | out->drawLink(link, catalog); |
260 | } | 260 | } |
261 | out->dump(); | 261 | out->dump(); |
262 | } | 262 | } |
263 | 263 | ||
264 | // draw non-link annotations | 264 | // draw non-link annotations |
265 | //~ need to reset CTM ??? | 265 | //~ need to reset CTM ??? |
266 | annotList = new Annots(xref, annots.fetch(xref, &obj)); | 266 | annotList = new Annots(xref, annots.fetch(xref, &obj)); |
267 | obj.free(); | 267 | obj.free(); |
268 | if (annotList->getNumAnnots() > 0) { | 268 | if (annotList->getNumAnnots() > 0) { |
269 | if (printCommands) { | 269 | if (printCommands) { |
270 | printf("***** Annotations\n"); | 270 | printf("***** Annotations\n"); |
271 | } | 271 | } |
272 | for (i = 0; i < annotList->getNumAnnots(); ++i) { | 272 | for (i = 0; i < annotList->getNumAnnots(); ++i) { |
273 | annotList->getAnnot(i)->draw(gfx); | 273 | annotList->getAnnot(i)->draw(gfx); |
274 | } | 274 | } |
275 | out->dump(); | 275 | out->dump(); |
276 | } | 276 | } |
277 | delete annotList; | 277 | delete annotList; |
278 | 278 | ||
279 | delete gfx; | 279 | delete gfx; |
280 | #endif | 280 | #endif |
281 | } | 281 | } |