Exemplo n.º 1
0
    def drawColorBars(self, e, origin):
        """Draw the color bars for offset printing color calibration.

        TODO: Add more types of color bars and switch from scaling PDF to
        drawing them by script
        TODO Get this to work for content of the parameter set.
        """

        showColorBars = e.showColorBars or (e.isPage and self.showColorBars)
        if not showColorBars:
            # Nothing to do.
            return

        ox, oy = point2D(origin)

        if ECI_GrayConL in showColorBars:
            path = getResourcesPath() + '/' + ECI_GrayConL
            if COLORBAR_LEFT in showColorBars:
                self.context.image(path, p=(ox - self.pl + pt(3), oy), h=e.h)

            # TODO: Does not generate the right position?
            if COLORBAR_RIGHT in showColorBars:
                self.context.image(path,
                                   p=(ox + e.w + self.pr * 2 / 3, oy),
                                   h=e.h)
Exemplo n.º 2
0
 def __init__(self, topic=None):
     resourcesPath = getResourcesPath()
     self.imagePaths = (
         resourcesPath + '/images/cookbot1.jpg',
         resourcesPath + '/images/cookbot10.jpg',
         resourcesPath + '/images/peppertom.png',
     )
     self.longTitles = []
     self.titles = []
     self.shortTitles = []
     self.newspaperNames = []
     self.headlines = []
     self.shortHeadlines = []
     self.credits = []
     self.ankeilers = []
     self.authors = []
     self.bylines = []
     self.captions = []
     self.summaries = []
     self.decks = []
     self.articles = []
     for cnt in self.MAX_ARTICLE_LENGTHS:
         self.longTitles.append(
             self.getBlurb('design_headline', 20, addPeriod=False))
         self.titles.append(
             self.getBlurb('design_article_title', 10, addPeriod=False))
         self.shortTitles.append(
             self.getBlurb('design_theory', 2, addPeriod=False))
         self.newspaperNames.append(
             self.getBlurb('news_newspapername', cnt, addPeriod=False))
         self.credits.append(self.getBlurb('credits', cnt))
         self.headlines.append(
             self.getBlurb('design_headline', cnt, addPeriod=False))
         self.shortHeadlines.append(
             self.getBlurb('design_theory', 4, addPeriod=False))
         self.ankeilers.append(self.getBlurb('ankeilers', cnt))
         self.bylines.append(self.getBlurb('design_article_byline', cnt))
         self.authors.append(
             self.getBlurb('design_article_author',
                           cnt=cnt,
                           addPeriod=False))
         self.captions.append(self.getBlurb('captions', cnt))
         self.summaries.append(self.getBlurb('summaries', cnt))
         self.decks.append(self.getBlurb('decks', cnt))
         self.articles.append(self.getBlurb('article', cnt))
Exemplo n.º 3
0
def hyphenatedWords(language=DEFAULT_LANGUAGE):
    """Answers the dictionary of hyphenated words for this language (default is
    English).


    >>> from pagebot.constants import LANGUAGE_EN, LANGUAGE_NL, LANGUAGE_DK, LANGUAGE_PT_BR
    >>> # English hyphenated words in the library.
    >>> words = hyphenatedWords(LANGUAGE_EN)
    >>> len(words)
    172372
    >>> #sorted(words.keys())[10]
    >>> #sorted(words.values())[10]
    >>> # Dutch hyphenated words in the library.
    >>> len(hyphenatedWords(LANGUAGE_NL))
    235900
    >>> # Brazilian-Portugese hyphenated words in the library.
    >>> len(hyphenatedWords(LANGUAGE_PT_BR))
    27436
    >>> # Danish hyphenated words in the library
    >>> len(hyphenatedWords(LANGUAGE_DK))
    183425
    """
    if language not in languages:
        # Not initialized yet, try to read.
        path = getResourcesPath() + '/languages/%s.txt' % language.lower()

        if os.path.exists(path):
            languages[language] = words = {}
            f = codecs.open(path, mode="r", encoding="utf-8")
            hyphenatedLines = f.read().split('\n')
            f.close()

            for line in hyphenatedLines:
                if line.startswith('#'):
                    continue
                key = line.replace('-', '')

                if len(key) == 0:
                    continue

                words[key] = line
    return languages.get(language)
Exemplo n.º 4
0
    def __init__(self, path=None):
        """Constructor of Sketch context.

        >>> import pysketchapp
        >>> from pagebot.document import Document
        >>> from pagebot.contexts import getContext
        >>> path = getResourcesPath() + '/sketch/TemplateSquare.sketch'
        >>> context = SketchContext(path) # Instead of context = getContext('Sketch')
        >>> # Context now interacts with the file.
        >>> # Create a PageBot Document instance, reading the Sketch file data as source.
        >>> doc = Document(context=context)
        >>> context.readDocument(doc)
        >>> page = doc[1]
        >>> page
        <Page #1 default (576pt, 783pt) E(7)>
        """
        """
        >>> # FIXME: Try reading the PageBot elements library
        >>> import pagebot
        >>> path = getResourcesPath() + '/sketch/PageBotElements.sketch'
        >>> context = SketchContext(path) # Instead of context = getContext('Sketch')
        >>> # Context now interacts with the file.
        >>> # Create a PageBot Document instance, reading the Sketch file data as source.
        >>> doc = Document(context=context)
        >>> context.readDocument(doc)
        """
        super().__init__()

        if path is None:
            path = getResourcesPath() + '/sketch/Template.sketch'

        self.name = self.__class__.__name__
        # Keep open connector to the file data. If path is None, a default resource
        # file is opened.
        self.setPath(path)  # Sets self.b to SketchBuilder(path)
        self.fileType = FILETYPE_SKETCH
        self.shape = None  # Current open shape
        self.w = self.h = None  # Optional default context size, overwriting the Sketch document.
        self._numberOfPages = 1
Exemplo n.º 5
0
def getTestFontsPath():
    """Answers the path of the PageBot test fonts."""
    resourcesPath = getResourcesPath()
    return '%s/%s' % (resourcesPath, 'testfonts')