Esempio n. 1
0
File: mesh.c Progetto: flaeddi/ulmsp
int create_hierarchy(const int       nLevel,          /* in       */
                     prealmatrix     coordinates,     /* in / out */
                     pindexmatrix    elements,        /* in / out */
                     prealvector     material,        /* in / out */
                     pindexmatrix    elements2edges,  /* in       */
                     pindexmatrix   *f2s,             /* out      */
                     const int       nBdry,           /* in       */
                     pcindexvector   bdrytyp,         /* in       */
                     pindexmatrix   *bdrylist,        /* in / out */
                     pindexvector   *bdry2edgeslist,  /* in / out */
                     pcrs           *A,               /* in / out */
                     pindexvector   *fixed)           /* out      */
{
  int i;
  pcoo S = new_coo(1,1,1);
  pindexmatrix edgeno;

  f2s = (pindexmatrix*) malloc((nLevel-1)*sizeof(pindexmatrix));
  fixed = (pindexvector*) malloc(nLevel*sizeof(pindexvector));
  edgeno = new_indexmatrix(0,0);

  if (!f2s || !fixed){
     free(f2s); free(fixed);
     return 0;
  }

  /* Store fixed for coarsest mesh*/
  getFixed(nBdry, bdrytyp, bdrylist, fixed[nLevel-1]);
  /* Refine mesh (nLevel-1) times */
  for (i=nLevel-2; i>=0; i--){  
    refine_uniform(coordinates, elements, material,
                   elements2edges, edgeno, bdrylist,
                   bdry2edgeslist, nBdry);
    getFixed(nBdry, bdrytyp, bdrylist, fixed[i]);
    f2s[i] = edgeno;
  }

  if (!(A==NULL)){
    A = (pcrs*) malloc(nLevel*sizeof(pcrs));

    if (!A || !fixed){
     free(A); free(fixed);
     return 0;
    }

    /* Build stiffness matrix for finest mesh */
    buildStiffness(coordinates, elements, S);
    A[0] = new_crs(1,1,1);
    init_coo2crs(A[0], S); 

    /* Build stiffness matrix for coarser meshes */
    for (i=1; i<nLevel; i++){
      buildStiffnessByInterpolation(A[i-1],A[i],f2s[i-1]);
    }
  }
  del_indexmatrix(edgeno);
  return 1;
}
Esempio n. 2
0
/*
 *	p r i n t
 */
returnValue Bounds::print( )
{
	if ( n == 0 )
		return SUCCESSFUL_RETURN;

	#ifndef __XPCTARGET__
	#ifndef __DSPACE__
	char myPrintfString[160];

	int nFR = getNFR( );
	int nFX = getNFX( );

	int* FR_idx;
	getFree( )->getNumberArray( &FR_idx );

	int* FX_idx;
	getFixed( )->getNumberArray( &FX_idx );

	snprintf( myPrintfString,160,"Bounds object comprising %d variables (%d free, %d fixed):\n",n,nFR,nFX );
	myPrintf( myPrintfString );

	REFER_NAMESPACE_QPOASES print( FR_idx,nFR,"free " );
	REFER_NAMESPACE_QPOASES print( FX_idx,nFX,"fixed" );

	#endif
	#endif

	return SUCCESSFUL_RETURN;
}
Esempio n. 3
0
/*
 *  p r i n t
 */
returnValue Bounds::print( )
{
    if ( n == 0 )
        return SUCCESSFUL_RETURN;

    #ifndef __SUPPRESSANYOUTPUT__

    char myPrintfString[MAX_STRING_LENGTH];

    int_t nFR = getNFR( );
    int_t nFX = getNFX( );

    int_t* FR_idx;
    getFree( )->getNumberArray( &FR_idx );

    int_t* FX_idx;
    getFixed( )->getNumberArray( &FX_idx );

    snprintf( myPrintfString,MAX_STRING_LENGTH,"Bounds object comprising %d variables (%d free, %d fixed):\n",(int)n,(int)nFR,(int)nFX );
    myPrintf( myPrintfString );

    REFER_NAMESPACE_QPOASES print( FR_idx,nFR,"free " );
    REFER_NAMESPACE_QPOASES print( FX_idx,nFX,"fixed" );

    #endif /* __SUPPRESSANYOUTPUT__ */

    return SUCCESSFUL_RETURN;
}
Esempio n. 4
0
/*
** This is the central routine of this section.
*/
void ttfont_CharStrings(TTStreamWriter& stream, struct TTFONT *font, std::vector<int>& glyph_ids)
    {
    Fixed post_format;

    /* The 'post' table format number. */
    post_format = getFixed( font->post_table );

    if( post_format.whole != 2 || post_format.fraction != 0 )
        throw TTException("TrueType fontdoes not have a format 2.0 'post' table");

    /* Emmit the start of the PostScript code to define the dictionary. */
    stream.printf("/CharStrings %d dict dup begin\n", glyph_ids.size());

    /* Emmit one key-value pair for each glyph. */
    for(std::vector<int>::const_iterator i = glyph_ids.begin();
        i != glyph_ids.end(); ++i)
        {
        if(font->target_type == PS_TYPE_42)     /* type 42 */
            {
            stream.printf("/%s %d def\n",ttfont_CharStrings_getname(font, *i), *i);
            }
        else                            /* type 3 */
            {
            stream.printf("/%s{",ttfont_CharStrings_getname(font, *i));

            tt_type3_charproc(stream, font, *i);

            stream.putline("}_d");      /* "} bind def" */
            }
        }

    stream.putline("end readonly def");
    } /* end of ttfont_CharStrings() */
Esempio n. 5
0
void Anon_obj::__Visit(hx::VisitContext *__inCtx)
{
   if (mFixedFields)
   {
      VariantKey *fixed = getFixed();
      for(int i=0;i<mFixedFields;i++)
         HX_VISIT_MEMBER(fixed[i].value);
   }
   HX_VISIT_MEMBER(mFields);
}
Esempio n. 6
0
void Anon_obj::__Mark(hx::MarkContext *__inCtx)
{
   if (mFixedFields)
   {
      VariantKey *fixed = getFixed();
      for(int i=0;i<mFixedFields;i++)
         HX_MARK_MEMBER(fixed[i].value);
   }
   HX_MARK_MEMBER(mFields);
}
void
CQIllustratorShape::
moveBy(const CPoint2D &d)
{
  assert(! getFixed());

  checkoutShape(CQIllustratorData::ChangeType::GEOMETRY);

  CMatrix2D m;

  m.setTranslation(d.x, d.y);

  transform(CPoint2D(0, 0), m);

  checkinShape(CQIllustratorData::ChangeType::GEOMETRY);
}
Esempio n. 8
0
inline int Anon_obj::findFixed(const ::String &inKey, bool inSkip5)
{
   if (!mFixedFields)
      return -1;
   VariantKey *fixed = getFixed();
   int sought = inKey.hash();

   if (!inSkip5)
   {
      if (mFixedFields<5)
      {
         for(int i=0;i<mFixedFields;i++)
            if (fixed[i].hash==sought && (fixed[i].key.__s == inKey.__s ||
                   (fixed[i].key.length == inKey.length && !memcmp(fixed[i].key.__s,inKey.__s, inKey.length))))
               return i;
         return -1;
      }
   }

   // Find node with same hash...
   /* hash example
      [0] = -3  <- min
      [1] = -1
      [2] = -1   (sought -1)
      [3] =  4
      [4] =  4  <- max
   */

   int min = inSkip5 ? 5 : 0;
   if (fixed[min].hash>sought)
      return -1;
   if (fixed[min].hash!=sought)
   {
      int max = mFixedFields;
      if (fixed[max-1].hash<sought)
         return -1;

      while(max>min+1)
      {
         int mid = (max+min)>>1;
         if (fixed[mid].hash <= sought)
            min = mid;
         else
            max = mid;
      }
   }
void
CQIllustratorShape::
draw(CQIllustratorShapeDrawer *drawer) const
{
  if (getFilter() != 0)
    drawGaussian(drawer);
  else
    drawShape(drawer);

  if (getFixed()) {
    const CBBox2D &bbox = getFlatBBox();

    drawer->pathInit();
    drawer->pathMoveTo(bbox.getLL());
    drawer->pathLineTo(bbox.getUR());
    drawer->pathStroke();

    drawer->pathInit();
    drawer->pathMoveTo(bbox.getLR());
    drawer->pathLineTo(bbox.getUL());
    drawer->pathStroke();
  }
}
Esempio n. 10
0
/*-----------------------------------------------------------
** Create the optional "FontInfo" sub-dictionary.
-----------------------------------------------------------*/
void ttfont_FontInfo(TTStreamWriter& stream, struct TTFONT *font)
{
    Fixed ItalicAngle;

    /* We create a sub dictionary named "FontInfo" where we */
    /* store information which though it is not used by the */
    /* interpreter, is useful to some programs which will */
    /* be printing with the font. */
    stream.putline("/FontInfo 10 dict dup begin");

    /* These names come from the TrueType font's "name" table. */
    stream.printf("/FamilyName (%s) def\n",font->FamilyName);
    stream.printf("/FullName (%s) def\n",font->FullName);

    if ( font->Copyright != (char*)NULL || font->Trademark != (char*)NULL )
    {
        stream.printf("/Notice (%s",
                      font->Copyright != (char*)NULL ? font->Copyright : "");
        stream.printf("%s%s) def\n",
                      font->Trademark != (char*)NULL ? " " : "",
                      font->Trademark != (char*)NULL ? font->Trademark : "");
    }

    /* This information is not quite correct. */
    stream.printf("/Weight (%s) def\n",font->Style);

    /* Some fonts have this as "version". */
    stream.printf("/Version (%s) def\n",font->Version);

    /* Some information from the "post" table. */
    ItalicAngle = getFixed( font->post_table + 4 );
    stream.printf("/ItalicAngle %d.%d def\n",ItalicAngle.whole,ItalicAngle.fraction);
    stream.printf("/isFixedPitch %s def\n", getULONG( font->post_table + 12 ) ? "true" : "false" );
    stream.printf("/UnderlinePosition %d def\n", (int)getFWord( font->post_table + 8 ) );
    stream.printf("/UnderlineThickness %d def\n", (int)getFWord( font->post_table + 10 ) );
    stream.putline("end readonly def");
} /* end of ttfont_FontInfo() */
Esempio n. 11
0
 Q_SLOT void worksWithCRCRLF() {
    for (int i = 0; i < data.size(); ++i) QCOMPARE(getFixed(data, i).d, dataFixed);
 }
Esempio n. 12
0
 Q_SLOT void worksWithCRLF() {
    const auto cr_lf = QByteArrayLiteral("\x00\x11\x0d\x0a\x33");
    const auto cr_lf_fixed = QByteArrayLiteral("\x00\x11\x0a\x33");
    for (int i = 0; i < cr_lf.size(); ++i)
       QCOMPARE(getFixed(cr_lf, i), (Result{cr_lf_fixed, true}));
 }
Esempio n. 13
0
 Q_SLOT void worksWithLFCR() {
    const auto lf_cr = QByteArrayLiteral("\x00\x11\x0a\x0d\x33");
    for (int i = 0; i < lf_cr.size(); ++i)
       QCOMPARE(getFixed(lf_cr, i), (Result{lf_cr, false}));
 }
Esempio n. 14
0
void read_font(const char *filename, font_type_enum target_type, std::vector<int>& glyph_ids, TTFONT& font)
{
    BYTE *ptr;

    /* Decide what type of PostScript font we will be generating. */
    font.target_type = target_type;

    if (font.target_type == PS_TYPE_42)
    {
        bool has_low = false;
        bool has_high = false;

        for (std::vector<int>::const_iterator i = glyph_ids.begin();
                i != glyph_ids.end(); ++i)
        {
            if (*i > 255)
            {
                has_high = true;
                if (has_low) break;
            }
            else
            {
                has_low = true;
                if (has_high) break;
            }
        }

        if (has_high && has_low)
        {
            font.target_type = PS_TYPE_42_3_HYBRID;
        }
        else if (has_high && !has_low)
        {
            font.target_type = PS_TYPE_3;
        }
    }

    /* Save the file name for error messages. */
    font.filename=filename;

    /* Open the font file */
    if ( (font.file = fopen(filename,"rb")) == (FILE*)NULL )
    {
        throw TTException("Failed to open TrueType font");
    }

    /* Allocate space for the unvarying part of the offset table. */
    assert(font.offset_table == NULL);
    font.offset_table = (BYTE*)calloc( 12, sizeof(BYTE) );

    /* Read the first part of the offset table. */
    if ( fread( font.offset_table, sizeof(BYTE), 12, font.file ) != 12 )
    {
        throw TTException("TrueType font may be corrupt (reason 1)");
    }

    /* Determine how many directory entries there are. */
    font.numTables = getUSHORT( font.offset_table + 4 );
#ifdef DEBUG_TRUETYPE
    debug("numTables=%d",(int)font.numTables);
#endif

    /* Expand the memory block to hold the whole thing. */
    font.offset_table = (BYTE*)realloc( font.offset_table, sizeof(BYTE) * (12 + font.numTables * 16) );

    /* Read the rest of the table directory. */
    if ( fread( font.offset_table + 12, sizeof(BYTE), (font.numTables*16), font.file ) != (font.numTables*16) )
    {
        throw TTException("TrueType font may be corrupt (reason 2)");
    }

    /* Extract information from the "Offset" table. */
    font.TTVersion = getFixed( font.offset_table );

    /* Load the "head" table and extract information from it. */
    ptr = GetTable(&font, "head");
    try
    {
        font.MfrRevision = getFixed( ptr + 4 );           /* font revision number */
        font.unitsPerEm = getUSHORT( ptr + 18 );
        font.HUPM = font.unitsPerEm / 2;
#ifdef DEBUG_TRUETYPE
        debug("unitsPerEm=%d",(int)font.unitsPerEm);
#endif
        font.llx = topost2( getFWord( ptr + 36 ) );               /* bounding box info */
        font.lly = topost2( getFWord( ptr + 38 ) );
        font.urx = topost2( getFWord( ptr + 40 ) );
        font.ury = topost2( getFWord( ptr + 42 ) );
        font.indexToLocFormat = getSHORT( ptr + 50 );     /* size of 'loca' data */
        if (font.indexToLocFormat != 0 && font.indexToLocFormat != 1)
        {
            throw TTException("TrueType font is unusable because indexToLocFormat != 0");
        }
        if ( getSHORT(ptr+52) != 0 )
        {
            throw TTException("TrueType font is unusable because glyphDataFormat != 0");
        }
    }
    catch (TTException& )
    {
        free(ptr);
        throw;
    }
    free(ptr);

    /* Load information from the "name" table. */
    Read_name(&font);

    /* We need to have the PostScript table around. */
    assert(font.post_table == NULL);
    font.post_table = GetTable(&font, "post");
    font.numGlyphs = getUSHORT( font.post_table + 32 );

    /* If we are generating a Type 3 font, we will need to */
    /* have the 'loca' and 'glyf' tables arround while */
    /* we are generating the CharStrings. */
    if (font.target_type == PS_TYPE_3 || font.target_type == PDF_TYPE_3 ||
            font.target_type == PS_TYPE_42_3_HYBRID)
    {
        BYTE *ptr;                      /* We need only one value */
        ptr = GetTable(&font, "hhea");
        font.numberOfHMetrics = getUSHORT(ptr + 34);
        free(ptr);

        assert(font.loca_table == NULL);
        font.loca_table = GetTable(&font,"loca");
        assert(font.glyf_table == NULL);
        font.glyf_table = GetTable(&font,"glyf");
        assert(font.hmtx_table == NULL);
        font.hmtx_table = GetTable(&font,"hmtx");
    }

    if (glyph_ids.size() == 0)
    {
        glyph_ids.clear();
        glyph_ids.reserve(font.numGlyphs);
        for (int x = 0; x < font.numGlyphs; ++x)
        {
            glyph_ids.push_back(x);
        }
    }
    else if (font.target_type == PS_TYPE_3 ||
             font.target_type == PS_TYPE_42_3_HYBRID)
    {
        ttfont_add_glyph_dependencies(&font, glyph_ids);
    }

} /* end of insert_ttfont() */