Пример #1
0
void InitVF(struct font_entry * tfontp)
{
  struct stat stat;
  unsigned char* position;
  int length;
  struct vf_char *tcharptr;  
  uint32_t c=0;
  struct font_num *tfontnump;  /* temporary font_num pointer   */
  
  DEBUG_PRINTF((DEBUG_DVI|DEBUG_VF),"\n  OPEN FONT:\t'%s'", tfontp->name);
  Message(BE_VERBOSE,"<%s>", tfontp->name);
  if ((tfontp->filedes = open(tfontp->name,O_RDONLY)) == -1) 
    Warning("font file %s could not be opened", tfontp->name);
  fstat(tfontp->filedes,&stat);
  tfontp->mmap = mmap(NULL,stat.st_size,
      PROT_READ, MAP_SHARED,tfontp->filedes,0);
  if (tfontp->mmap == (unsigned char *)-1) 
    Fatal("cannot mmap VF file <%s> !\n",currentfont->name);
  if (*(tfontp->mmap) != PRE) 
    Fatal("unknown font format in file <%s> !\n",currentfont->name);
  if (*(tfontp->mmap+1) != VF_ID) 
      Fatal( "wrong version of vf file!  (%d should be 202)\n",
	     (int)*(tfontp->mmap+1));
  DEBUG_PRINTF2(DEBUG_VF,"\n  VF_PRE:\t'%.*s'", 
		(int)*(tfontp->mmap+2), tfontp->mmap+3);
  position = tfontp->mmap+3 + *(tfontp->mmap+2);
  c=UNumRead(position, 4);
  DEBUG_PRINTF(DEBUG_VF," %d", c);
  CheckChecksum (tfontp->c, c, tfontp->name);
  tfontp->designsize = UNumRead(position+4,4);
  DEBUG_PRINTF(DEBUG_VF," %d", tfontp->designsize);
  tfontp->type = FONT_TYPE_VF;
  tfontp->vffontnump=NULL;
  /* Read font definitions */
  position += 8;
  while(*position >= FNT_DEF1 && *position <= FNT_DEF4) {
    DEBUG_PRINTF2(DEBUG_VF,"\n  @%ld VF:\t%s", 
		  (long)(position - tfontp->mmap), 
		  dvi_commands[*position]);
    FontDef(position,tfontp);	
    length = dvi_commandlength[*position];
    position += length + *(position + length-1) + *(position+length-2);
  }
  /* Default font is the first defined */
  tfontnump = tfontp->vffontnump;
  while (tfontnump->next != NULL) {
    tfontnump = tfontnump->next;
  }
  tfontp->defaultfont=tfontnump->k;
  
  /* Read char definitions */
  while(*position < FNT_DEF1) {
    DEBUG_PRINTF(DEBUG_VF,"\n@%ld VF CHAR:\t", 
		 (long)(position - tfontp->mmap));
    tcharptr=xmalloc(sizeof(struct vf_char));
    switch (*position) {
    case LONG_CHAR:
      tcharptr->length = UNumRead(position+1,4);
      c = UNumRead(position+5,4);
      tcharptr->tfmw = UNumRead(position+9,4);
      position += 13;
      break;
    default:
      tcharptr->length = UNumRead(position,1);
      c = UNumRead(position+1,1);
      tcharptr->tfmw = UNumRead(position+2,3);
      position += 5;
    }
    DEBUG_PRINTF2(DEBUG_VF,"%d %d",tcharptr->length,c);
    DEBUG_PRINTF(DEBUG_VF," %d",tcharptr->tfmw);
    tcharptr->tfmw = (int32_t) 
      ((int64_t) tcharptr->tfmw * tfontp->s / (1 << 20));
    DEBUG_PRINTF(DEBUG_VF," (%d)",tcharptr->tfmw);
    if (c > NFNTCHARS) /* Only positive for now */
      Fatal("vf character exceeds numbering limit");
    tfontp->chr[c] = tcharptr;
    tcharptr->mmap=position;
    position += tcharptr->length;
  }
}
Пример #2
0
void FontSelectFrame::setFontsDirectory(QString dir_name) {

    if (m_config) m_config->setPath(dir_name);

    m_database.clear();



    ui->lineEditFontsDir->setText(dir_name);

    FT_Library library = 0;

    int error = FT_Init_FreeType(&library);
    if (error) {
        qDebug() << "FT_Open_Library error " << error;
        return;
    }


    QDir dir(dir_name);
    QStringList files = dir.entryList(
            QStringList()
            << "*.ttf"
            << "*.pcf"
            << "*.ttc"
            << "*.pcf.gz"
            << "*.otf",
            QDir::Files | QDir::Readable
            );
    QProgressDialog* progress = 0;
    if (!files.isEmpty()) {
        progress = new QProgressDialog(
                tr("Scanning directory.."),
                tr("Cancel"),
                0,files.size(),this);
        progress->setCancelButton(0);
        progress->setWindowModality(Qt::WindowModal);
        //progress->show();
    }
    int progress_val = 0;
    foreach (QString file_name, files) {
        //qDebug() << "found font file : " << file_name;
        QFile file(dir.filePath(file_name));
        if (file.open(QFile::ReadOnly)) {
            QByteArray bytes = file.readAll();
            const FT_Byte* data = reinterpret_cast<const FT_Byte* >(bytes.data());
            FT_Face face;
            int error =  FT_New_Memory_Face(library,
                                            data,bytes.size(),-1,&face);
            if (error==0) {
                int faces_num = face->num_faces;
                FT_Done_Face(face);
                for (int face_n = 0;face_n<faces_num;face_n++) {
                    error =  FT_New_Memory_Face(library,
                                                data,bytes.size(),face_n,&face);
                    /// skip font if load error
                    if (error!=0)  continue;

                    QString family = face->family_name;
                    //qDebug() << "face " << family << " "
                    //        << face->style_name;
                    /// skip font if not have family
                    if (family.isEmpty()) continue;

                    bool fixedsizes = (FT_FACE_FLAG_SCALABLE & face->face_flags ) == 0;
                    m_database[face->family_name].push_back(
                            FontDef(face->style_name,
                                    file_name,
                                    face_n,
                                    fixedsizes));
                    if (fixedsizes) {
                        for (int i=0;i<face->num_fixed_sizes;i++) {
                            m_database[family].back().fixedsizes.push_back(
                                    QPair<int,int>(
                                            face->available_sizes[i].width,
                                            face->available_sizes[i].height));
                        }
                        qDebug() << " fixed sizes " << m_database[family].back().fixedsizes;

                    }

                    FT_Done_Face(face);

                }
            }

        }

        progress_val++;
        progress->setValue(progress_val);
    }