According to legend, the arms of Barcelona were origially plain gold: in heraldic terms "Or plain". Geoffroy le Velu, Count of Barcelona, was mortally wounded fighting on the side of Charles le Chauve against the Normans. Charles, to show his gratitude for Geoffroy's bravery, dipped his fingers in his blood and smeared them onto the shield, making the present arms, in heraldic terms "Or four pallets gules".
When the Counts of Barcelona became Kings of Aragón, the two territories of Aragon and Catalonia were united under one monarch. Since then they have both used the same arms
Unusually the flags of the Counts of Barcelona and Kings of Aragón are the arms rotated through 90 degrees: ie four red horizonatal stripes on a gold background. Of course on the Count-King's coat of arms (shown below right) the stripes would go both directions.
Aragonese teritorries stretched far north of the the Pyrenees ( Pirenčus, Pirineus, Pyrénées) in the Middle Ages - as far north as Provence. Catalonia straddled what is now the French-Spanish border - a border which dates only from the Treaty of the Pyrenees in 1659.
Most of the northern part of Catalonia was part of the County of the Roussillon. For the purposes of the French administration the Roussillon has now been tacked onto the Languedoc - hence the name of the Languedoc-Roussillon région.
Just to complicate matters, the département which corresponds to the Roussillon is called the Pyrénées-Orientales, but it still uses the arms of the Roussillon (identical to those of Aragón) and you will see the Catalan flag used everywhere there.