Changeset a35b458 in mainline for uspace/lib/draw/font/pcf.c


Ignore:
Timestamp:
2018-03-02T20:10:49Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/draw/font/pcf.c

    r3061bc1 ra35b458  
    151151{
    152152        pcf_data_t *data = (pcf_data_t *) opaque_data;
    153        
     153
    154154        /* TODO is this correct? */
    155155        uint8_t byte1 = (chr >> 8) & 0xff;
     
    160160            (byte1 - e->min_byte1) * (e->max_byte2 - e->min_byte2 + 1) +
    161161            (byte2 - e->min_byte2);
    162        
     162
    163163        aoff64_t entry_offset = data->encodings_table.offset +
    164164            (sizeof(uint32_t) + 5 * sizeof(uint16_t)) +
    165165            entry_index * sizeof(uint16_t);
    166        
     166
    167167        int rc = fseek(data->file, entry_offset, SEEK_SET);
    168168        if (rc != 0)
    169169                return errno;
    170        
     170
    171171        uint16_t glyph = 0;
    172172        size_t records_read = fread(&glyph, sizeof(uint16_t), 1, data->file);
    173173        if (records_read != 1)
    174174                return EINVAL;
    175        
     175
    176176        glyph = uint16_t_pcf2host(glyph, data->encodings_table.format);
    177        
     177
    178178        if (glyph == 0xffff)
    179179                return ENOENT;
    180        
     180
    181181        *glyph_id = glyph;
    182        
     182
    183183        return EOK;
    184184}
     
    190190        int rc;
    191191        size_t records_read;
    192        
     192
    193193        if (table->format & PCF_FORMAT_COMPRESSED_METRICS) {
    194194                offset = table->offset + sizeof(uint32_t) + sizeof(uint16_t) +
    195195                    glyph_id * sizeof(pcf_compressed_metrics_t);
    196                
     196
    197197                rc = fseek(data->file, offset, SEEK_SET);
    198198                if (rc != 0)
    199199                        return errno;
    200                
     200
    201201                pcf_compressed_metrics_t compressed_metrics;
    202202                records_read = fread(&compressed_metrics,
     
    204204                if (records_read != 1)
    205205                        return EINVAL;
    206                
     206
    207207                metrics->left_side_bearing =
    208208                    compressed2int(compressed_metrics.left_side_bearing);
     
    220220                offset = table->offset + 2 * sizeof(uint32_t) +
    221221                    glyph_id * sizeof(pcf_default_metrics_t);
    222                
     222
    223223                rc = fseek(data->file, offset, SEEK_SET);
    224224                if (rc != 0)
    225225                        return errno;
    226        
     226
    227227                pcf_default_metrics_t uncompressed_metrics;
    228228                records_read = fread(&uncompressed_metrics,
     
    230230                if (records_read != 1)
    231231                        return EINVAL;
    232                
     232
    233233                metrics->left_side_bearing =
    234234                    int16_t_pcf2host(uncompressed_metrics.left_side_bearing,
     
    250250                    table->format);
    251251        }
    252        
     252
    253253        return EOK;
    254254}
     
    258258{
    259259        pcf_data_t *data = (pcf_data_t *) opaque_data;
    260        
     260
    261261        pcf_default_metrics_t pcf_metrics;
    262262        memset(&pcf_metrics, 0, sizeof(pcf_default_metrics_t));
     
    265265        if (rc != EOK)
    266266                return rc;
    267        
     267
    268268        aoff64_t offset = data->bitmap_table.offset + (2 * sizeof(uint32_t)) +
    269269            (glyph_id * sizeof(uint32_t));
    270        
     270
    271271        if (fseek(data->file, offset, SEEK_SET) < 0)
    272272                return errno;
    273        
     273
    274274        uint32_t bitmap_offset = 0;
    275275        size_t records_read = fread(&bitmap_offset, sizeof(uint32_t), 1,
     
    279279        bitmap_offset = uint32_t_pcf2host(bitmap_offset,
    280280            data->bitmap_table.format);
    281        
     281
    282282        offset = data->bitmap_table.offset + (2 * sizeof(uint32_t)) +
    283283            (data->glyph_count * sizeof(uint32_t)) + (4 * sizeof(uint32_t))
    284284            + bitmap_offset;
    285        
     285
    286286        if (fseek(data->file, offset, SEEK_SET) < 0)
    287287                return errno;
    288        
     288
    289289        surface_coord_t width = pcf_metrics.character_width;
    290290        surface_coord_t height = pcf_metrics.character_ascent +
     
    294294        size_t row_bytes = ALIGN_UP(ALIGN_UP(width, 8) / 8, row_padding_bytes);
    295295        size_t bitmap_bytes = height * row_bytes;
    296        
     296
    297297        uint8_t *bitmap = malloc(bitmap_bytes);
    298298        if (bitmap == NULL)
    299299                return ENOMEM;
    300        
     300
    301301        records_read = fread(bitmap, sizeof(uint8_t), bitmap_bytes,
    302302            data->file);
    303        
     303
    304304        surface_t *surface = surface_create(width, height, NULL, 0);
    305305        if (!surface) {
     
    307307                return ENOMEM;
    308308        }
    309        
     309
    310310        for (unsigned int y = 0; y < height; ++y) {
    311311                size_t row_offset = row_bytes * y;
     
    334334                }
    335335        }
    336        
     336
    337337        *out_surface = surface;
    338338        free(bitmap);
     
    344344{
    345345        pcf_data_t *data = (pcf_data_t *) opaque_data;
    346        
     346
    347347        pcf_default_metrics_t pcf_metrics;
    348348        memset(&pcf_metrics, 0, sizeof(pcf_default_metrics_t));
     
    351351        if (rc != EOK)
    352352                return rc;
    353        
     353
    354354        gm->left_side_bearing = pcf_metrics.left_side_bearing;
    355355        gm->width = pcf_metrics.character_width;
     
    359359            pcf_metrics.character_ascent;
    360360        gm->ascender = pcf_metrics.character_ascent;
    361        
     361
    362362        return EOK;
    363363}
     
    366366{
    367367        pcf_data_t *data = (pcf_data_t *) opaque_data;
    368        
     368
    369369        fclose(data->file);
    370370        free(data);
     
    383383        if (rc != 0)
    384384                return errno;
    385        
     385
    386386        aoff64_t file_size = ftell(data->file);
    387        
     387
    388388        rc = fseek(data->file, 0, SEEK_SET);
    389389        if (rc != 0)
    390390                return errno;
    391        
     391
    392392        char header[4];
    393393        size_t records_read = fread(header, sizeof(char), 4, data->file);
    394394        if (records_read != 4)
    395395                return EINVAL;
    396        
     396
    397397        if (header[0] != 1 || header[1] != 'f' || header[2] != 'c' ||
    398398            header[3] != 'p')
    399399                return EINVAL;
    400        
     400
    401401        uint32_t table_count;
    402402        records_read = fread(&table_count, sizeof(uint32_t), 1,
     
    404404        if (records_read != 1)
    405405                return EINVAL;
    406        
     406
    407407        table_count = uint32_t_le2host(table_count);
    408        
     408
    409409        bool found_bitmap_table = false;
    410410        bool found_metrics_table = false;
    411411        bool found_encodings_table = false;
    412412        bool found_accelerators_table = false;
    413        
     413
    414414        for (uint32_t index = 0; index < table_count; index++) {
    415415                pcf_toc_entry_t toc_entry;
     
    420420                toc_entry.size = uint32_t_le2host(toc_entry.size);
    421421                toc_entry.offset = uint32_t_le2host(toc_entry.offset);
    422                
     422
    423423                if (toc_entry.offset >= file_size)
    424424                        continue;
    425                
     425
    426426                aoff64_t end = ((aoff64_t) toc_entry.offset) + ((aoff64_t) toc_entry.size);
    427427                if (end > file_size)
    428428                        continue;
    429                
     429
    430430                if (toc_entry.type == PCF_TABLE_BITMAPS) {
    431431                        if (found_bitmap_table)
     
    453453                }
    454454        }
    455        
     455
    456456        if (!found_bitmap_table || !found_metrics_table ||
    457457            !found_encodings_table || !found_accelerators_table)
    458458                return EINVAL;
    459        
     459
    460460        return EOK;
    461461}
     
    467467        if (rc != 0)
    468468                return errno;
    469        
     469
    470470        size_t records_read = fread(&format, sizeof(uint32_t), 1, data->file);
    471471        if (records_read != 1)
    472472                return EINVAL;
    473        
     473
    474474        format = uint32_t_le2host(format);
    475475        if (format != table->format)
    476476                return EINVAL;
    477        
     477
    478478        return EOK;
    479479}
     
    484484        if (rc != EOK)
    485485                return rc;
    486        
     486
    487487        if ((data->bitmap_table.format & PCF_FORMAT_MASK) != PCF_FORMAT_DEFAULT)
    488488                return EINVAL;
    489        
     489
    490490        uint32_t glyph_count = 0;
    491491        size_t records_read = fread(&glyph_count, sizeof(uint32_t), 1,
     
    504504        if (rc != EOK)
    505505                return rc;
    506        
     506
    507507        size_t records_read;
    508508        uint32_t metrics_count;
     
    525525                    data->metrics_table.format);
    526526        }
    527        
     527
    528528        if (metrics_count != data->glyph_count)
    529529                return EINVAL;
    530        
     530
    531531        return EOK;
    532532}
     
    537537        if (rc != EOK)
    538538                return rc;
    539        
     539
    540540        pcf_encoding_t encoding;
    541541        size_t records_read = fread(&encoding, sizeof(pcf_encoding_t), 1,
     
    543543        if (records_read != 1)
    544544                return EINVAL;
    545        
     545
    546546        encoding.min_byte1 = uint16_t_pcf2host(encoding.min_byte1,
    547547            data->encodings_table.format);
     
    554554        encoding.default_char = uint16_t_pcf2host(encoding.default_char,
    555555            data->encodings_table.format);
    556        
     556
    557557        data->encoding = encoding;
    558558        return EOK;
     
    564564        if (rc != EOK)
    565565                return rc;
    566        
     566
    567567        pcf_accelerators_t accelerators;
    568568        size_t records_read = fread(&accelerators, sizeof(pcf_accelerators_t),
     
    570570        if (records_read != 1)
    571571                return EINVAL;
    572        
     572
    573573        data->font_metrics.ascender = int32_t_pcf2host(accelerators.font_ascent,
    574574            data->accelerators_table.format);
     
    576576            data->accelerators_table.format);
    577577        data->font_metrics.leading = 0;
    578        
     578
    579579        return EOK;
    580580}
     
    586586        if (data == NULL)
    587587                return ENOMEM;
    588        
     588
    589589        data->file = fopen(filename, "rb");
    590590        if (data->file == NULL)
    591591                goto read_error;
    592        
     592
    593593        rc = pcf_read_toc(data);
    594594        if (rc != EOK)
    595595                goto error;
    596        
     596
    597597        rc = pcf_read_bitmap_table_header(data);
    598598        if (rc != EOK)
    599599                goto error;
    600        
     600
    601601        rc = pcf_read_metrics_table_header(data);
    602602        if (rc != EOK)
    603603                goto error;
    604        
     604
    605605        rc = pcf_read_encodings_table_header(data);
    606606        if (rc != EOK)
    607607                goto error;
    608        
     608
    609609        rc = pcf_read_accelerators_table(data);
    610610        if (rc != EOK)
    611611                goto error;
    612        
     612
    613613        rc = bitmap_font_create(&fd_pcf, data, data->glyph_count,
    614614            data->font_metrics, points, font);
    615615        if (rc != EOK)
    616616                goto error;
    617        
     617
    618618        return EOK;
    619619read_error:
Note: See TracChangeset for help on using the changeset viewer.