示例#1
0
    def makeGlyphArray(self,neumeChunks,lyrics = None):
        lyricArray = re.split(' ',lyrics)
        i, lPtr = 0, 0
        gArray = []
        while(i < len(neumeChunks)):
            # Grab next chunk
            nc = neumeChunks[i]
            if (neume_dict.takesLyric(nc[0])):
                # chunk needs a lyric
                if (lPtr < len(lyricArray)):
                    lyr = lyricArray[lPtr]
                else:
                    lyr = ' '
                lPtr += 1
                g = Glyph(neumes=neume_dict.translate(nc),lyrics=lyr)
                # To Do: see if lyric ends with '_' and if lyrics are
                # wider than the neume, then combine with next chunk
            else: 
                # no lyric needed
                g = Glyph(neume_dict.translate(nc))
            g.calc_width(self.neumeFont['font'], self.neumeFont['font_size'], self.lyricFont['font'], self.lyricFont['font_size'])

            gArray.append(g)
            i += 1
        return gArray
示例#2
0
 def linebreak(self,neumes,lyrics = None):
     """Break neumes and lyrics into lines"""
     cr = Cursor(0,0)
     lyricArray = re.split(' ',lyrics)
     # If lyric spans multiple neumes
     #   then see if lyric is wider than span
     #   else see if width of glypch is max of neume and lyric
     charSpace = 4 # default space between characters
     textOffset = 20 # default space lyrics appear below neumes
     #neumeArray = neume_dict.translate(neumes).split(' ')
     neumeArray = neumes.split(' ')
     neumePos = []
     lyricPos = []
     lyricIdx = 0
     for neume in neumeArray:
         #print("Neume length: " + str(pdfmetrics.stringWidth(neume,'EZ Psaltica',24)))
         nWidth = pdfmetrics.stringWidth(neume_dict.translate(neume),'EZ Psaltica',self.nFontSize)
         if nWidth > 1.0: # if it's not a gorgon or other small symbol
             # Neume might take lyric
             if lyricIdx < len(lyricArray):
                 lyr = lyricArray[lyricIdx]
             else:
                 lyr = ""
             lWidth = pdfmetrics.stringWidth(lyr,lyric_attrib['font'],lyric_attrib['font_size'])
             # Glyph width will be the max of the two if lyric isn't stretched out
             # across multiple neumes
             addLyric = False
             #if (lyr[-1] != "_") & (neume_dict.takesLyric(neume)):
             if (neume_dict.takesLyric(neume)):
                 glWidth = max(nWidth,lWidth)
                 lyricIdx += 1
                 addLyric = True
             else:
                 glWidth = nWidth
             if (glWidth + cr.x) >= self.lineWidth: # line break
                 cr.x, cr.y = 0, cr.y - self.lineHeight
                 # does it take a lyric syllable?
                 neumePos.append((cr.x,cr.y,neume_dict.translate(neume)))
             else: # no line break
                 # does it take a lyric syllable?
                 neumePos.append((cr.x,cr.y,neume_dict.translate(neume)))
             if (addLyric):
                 lyricPos.append((cr.x,cr.y-textOffset,lyr))
             cr.x += glWidth + charSpace
             
         else:
             # offsets for gorgon
             # offsets for apli
             # offset for kentima
             # offsets for omalon
             # offsets for antikenoma
             # offsets for eteron
             neumePos.append((cr.x - charSpace,cr.y,neume_dict.translate(neume)))
         
     #print neumePos
     return neumePos, lyricPos